]> code.delx.au - gnu-emacs/blobdiff - lisp/newcomment.el
Add fullscreen_hook.
[gnu-emacs] / lisp / newcomment.el
index 877d5c9f399c1cdb38ae0fbb2569fc65588d7f67..9d089a2e164045056200bc950e7042eb2033c6f2 100644 (file)
@@ -104,25 +104,30 @@ not to go beyond `comment-fill-column'."
   :type 'integer
   :group 'comment)
 (make-variable-buffer-local 'comment-column)
+;;;###autoload(put 'comment-column 'safe-local-variable 'integerp)
 
 ;;;###autoload
 (defvar comment-start nil
   "*String to insert to start a new comment, or nil if no comment syntax.")
+;;;###autoload(put 'comment-start 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-start-skip nil
   "*Regexp to match the start of a comment plus everything up to its body.
 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
 at the place matched by the close of the first pair.")
+;;;###autoload(put 'comment-start-skip 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-end-skip nil
   "Regexp to match the end of a comment plus everything up to its body.")
+;;;###autoload(put 'comment-end-skip 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-end ""
   "*String to insert to end a new comment.
 Should be an empty string if comments are terminated by end-of-line.")
+;;;###autoload(put 'comment-end 'safe-local-variable 'string-or-null-p)
 
 ;;;###autoload
 (defvar comment-indent-function 'comment-indent-default
@@ -233,7 +238,7 @@ behavior for explicit filling, you might as well use \\[newline-and-indent]."
 (defcustom comment-empty-lines nil
   "If nil, `comment-region' does not comment out empty lines.
 If t, it always comments out empty lines.
-if `eol' it only comments out empty lines if comments are
+If `eol' it only comments out empty lines if comments are
 terminated by the end of line (i.e. `comment-end' is empty)."
   :type '(choice (const :tag "Never" nil)
          (const :tag "Always" t)
@@ -294,7 +299,7 @@ the variables are properly set."
                   (substring comment-start 1)))
       ;; Hasn't been necessary yet.
       ;; (unless (string-match comment-start-skip comment-continue)
-      ;;       (kill-local-variable 'comment-continue))
+      ;;       (kill-local-variable 'comment-continue))
       )
     ;; comment-skip regexps
     (unless (and comment-start-skip
@@ -594,11 +599,16 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any."
                    (if (and other (<= other max) (> other min))
                        ;; There is a comment and it's in the range: bingo.
                        (setq indent other))))))))
+       ;; Update INDENT to leave at least one space
+       ;; after other nonwhite text on the line.
+       (save-excursion
+         (skip-chars-backward " \t")
+         (unless (bolp)
+           (setq indent (max indent (1+ (current-column))))))
+       ;; If that's different from comment's current position, change it.
        (unless (= (current-column) indent)
-         ;; If that's different from current, change it.
          (delete-region (point) (progn (skip-chars-backward " \t") (point)))
-         (indent-to (if (bolp) indent
-                      (max indent (1+ (current-column)))))))
+         (indent-to indent)))
       (goto-char cpos)
       (set-marker cpos nil))))
 
@@ -759,7 +769,7 @@ comment markers."
            (box-equal nil))       ;Whether we might be using `=' for boxes.
        (save-restriction
          (narrow-to-region spt ept)
-               
+
          ;; Remove the comment-start.
          (goto-char ipt)
          (skip-syntax-backward " ")
@@ -788,7 +798,7 @@ comment markers."
              ;; If there's something left but it doesn't look like
              ;; a comment-start any more, just remove it.
              (delete-region (point-min) (point))))
-               
+
          ;; Remove the end-comment (and leading padding and such).
          (goto-char (point-max)) (comment-enter-backward)
          ;; Check for special `=' used sometimes in comment-box.
@@ -1052,11 +1062,13 @@ The strings used as comment starts are built from
        lines
        (nth 3 style))))))
 
+;;;###autoload
 (defun comment-box (beg end &optional arg)
   "Comment out the BEG .. END region, putting it inside a box.
 The numeric prefix ARG specifies how many characters to add to begin- and
 end- comment markers additionally to what `comment-add' already specifies."
   (interactive "*r\np")
+  (comment-normalize-vars)
   (let ((comment-style (if (cadr (assoc comment-style comment-styles))
                           'box-multi 'box)))
     (comment-region beg end (+ comment-add arg))))
@@ -1112,12 +1124,44 @@ This has no effect in modes that do not define a comment syntax."
   :group 'comment)
 
 (defun comment-valid-prefix-p (prefix compos)
-  (or
-   ;; Accept any prefix if the current comment is not EOL-terminated.
-   (save-excursion (goto-char compos) (comment-forward) (not (bolp)))
-   ;; Accept any prefix that starts with a comment-start marker.
-   (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
-                prefix)))
+    "Check that the adaptive-fill-prefix is consistent with the context.
+PREFIX is the prefix (presumably guessed by `adaptive-fill-mode').
+COMPOS is the position of the beginning of the comment we're in, or nil
+if we're not inside a comment."
+  ;; This consistency checking is mostly needed to workaround the limitation
+  ;; of auto-fill-mode whose paragraph-determination doesn't pay attention
+  ;; to comment boundaries.
+  (if (null compos)
+      ;; We're not inside a comment: the prefix shouldn't match
+      ;; a comment-starter.
+      (not (and comment-start comment-start-skip
+                (string-match comment-start-skip prefix)))
+    (or
+     ;; Accept any prefix if the current comment is not EOL-terminated.
+     (save-excursion (goto-char compos) (comment-forward) (not (bolp)))
+     ;; Accept any prefix that starts with the same comment-start marker
+     ;; as the current one.
+     (when (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
+                         prefix)
+       (let ((prefix-com (comment-string-strip (match-string 0 prefix) nil t)))
+         (string-match "\\`[ \t]*" prefix-com)
+         (let* ((prefix-space (match-string 0 prefix-com))
+                (prefix-indent (string-width prefix-space))
+                (prefix-comstart (substring prefix-com (match-end 0))))
+           (save-excursion
+             (goto-char compos)
+             ;; The comstart marker is the same.
+             (and (looking-at (regexp-quote prefix-comstart))
+                  ;; The indentation as well.
+                  (or (= prefix-indent
+                         (- (current-column) (current-left-margin)))
+                      ;; Check the indentation in two different ways, just
+                      ;; to try and avoid most of the potential funny cases.
+                      (equal prefix-space
+                             (buffer-substring (point)
+                                               (progn (move-to-left-margin)
+                                                      (point)))))))))))))
+                    
 
 ;;;###autoload
 (defun comment-indent-new-line (&optional soft)
@@ -1170,8 +1214,7 @@ unless optional argument SOFT is non-nil."
         ;; If there's an adaptive prefix, use it unless we're inside
         ;; a comment and the prefix is not a comment starter.
         ((and fill-prefix
-              (or (not compos)
-                  (comment-valid-prefix-p fill-prefix compos)))
+               (comment-valid-prefix-p fill-prefix compos))
          (indent-to-left-margin)
          (insert-and-inherit fill-prefix))
         ;; If we're not inside a comment, just try to indent.