]> code.delx.au - gnu-emacs/commitdiff
* lisp/files-x.el (modify-file-local-variable-prop-line): Add local
authorJuri Linkov <juri@jurta.org>
Sat, 15 Jun 2013 22:44:38 +0000 (01:44 +0300)
committerJuri Linkov <juri@jurta.org>
Sat, 15 Jun 2013 22:44:38 +0000 (01:44 +0300)
variables to the end of the existing comment on the first line.
Use `file-auto-mode-skip' to skip interpreter magic line,
and also skip XML declaration.

lisp/ChangeLog
lisp/files-x.el

index 919772659ea28417636ff3aea29c915437f5a795..f7f42011575de5b88fdf73a19a68600186e1ea1e 100644 (file)
@@ -1,3 +1,10 @@
+2013-06-15  Juri Linkov  <juri@jurta.org>
+
+       * files-x.el (modify-file-local-variable-prop-line): Add local
+       variables to the end of the existing comment on the first line.
+       Use `file-auto-mode-skip' to skip interpreter magic line,
+       and also skip XML declaration.
+
 2013-06-15  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * startup.el (package--builtin-versions): New var.
index 0ba245d423ab757c1e4fb2a39365030cccd7392b..2ae1a0e404571b959299210464a3c9b35ba7010d 100644 (file)
@@ -256,19 +256,40 @@ from the -*- line ignoring the input argument VALUE."
 
        (goto-char (point-min))
 
-       ;; Skip interpreter magic line "#!"
-       (when (looking-at "^\\(#!\\|'\\\\\"\\)")
+       ;; Skip interpreter magic line "#!" or XML declaration.
+       (when (or (looking-at file-auto-mode-skip)
+                 (looking-at "<\\?xml[^>\n]*>$"))
          (forward-line 1))
 
+       (comment-normalize-vars)
        (let ((comment-style 'plain)
-             (comment-start (or comment-start ";;; ")))
-         (comment-region
-          (prog1 (point)
-            (insert "-*-")
-            (setq beg (point-marker))
-            (setq end (point-marker))
-            (insert "-*-\n"))
-          (point))))
+             (comment-start (or comment-start ";;; "))
+             (line-beg (line-beginning-position))
+             (ce nil))
+         ;; If the first line contains a comment.
+         (if (save-excursion
+               (and (looking-at comment-start-skip)
+                    (goto-char (match-end 0))
+                    (re-search-forward comment-end-skip)
+                    (goto-char (match-beginning 0))
+                    ;; Still on the same line?
+                    (equal line-beg (line-beginning-position))
+                    (setq ce (point))))
+             ;; Add local variables to the end of the existing comment.
+             (progn
+               (goto-char ce)
+               (insert "  -*-")
+               (setq beg (point-marker))
+               (setq end (point-marker))
+               (insert "-*-"))
+           ;; Otherwise, add a new comment before the first line.
+           (comment-region
+            (prog1 (point)
+              (insert "-*-")
+              (setq beg (point-marker))
+              (setq end (point-marker))
+              (insert "-*-\n"))
+            (point)))))
 
       (cond
        ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")