emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

add-file-local-variable (was: [ELPA-diffs] elpa r408: * packages/auctex/


From: Juri Linkov
Subject: add-file-local-variable (was: [ELPA-diffs] elpa r408: * packages/auctex/tex-jp.el: Add coding cookie.)
Date: Sat, 15 Jun 2013 00:44:50 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu)

>> +;; -*- coding: iso-2022-jp-unix; -*-
>> +
>>  ;;; tex-jp.el --- Support for Japanese TeX.
>
> Elisp files should start with ";;; <name> --- <desc>", so please use
>
>>  ;;; tex-jp.el --- Support for Japanese TeX.  -*- coding: iso-2022-jp-unix; 
>> -*-
>
> instead, even though it spills over the sacred 80-columns limit.

`add-file-local-variable-prop-line' currently inserts local variables
such as `coding' and `lexical-binding' before the header line,
thus breaking this convention.

If the following is a sufficiently general approach, it should add
local variables to the end of the comment on the first line in any mode:

=== modified file 'lisp/files-x.el'
--- lisp/files-x.el     2013-01-01 09:11:05 +0000
+++ lisp/files-x.el     2013-06-14 21:38:37 +0000
@@ -261,14 +264,34 @@ (defun modify-file-local-variable-prop-l
          (forward-line 1))
 
        (let ((comment-style 'plain)
-             (comment-start (or comment-start ";;; ")))
+             (comment-start (or comment-start ";;; "))
+             (line-beg (line-beginning-position))
+             (ce nil))
+         (comment-normalize-vars)
+         ;; 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, create a new comment before the first line.
          (comment-region
           (prog1 (point)
             (insert "-*-")
             (setq beg (point-marker))
             (setq end (point-marker))
             (insert "-*-\n"))
-          (point))))
+            (point)))))
 
       (cond
        ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")




reply via email to

[Prev in Thread] Current Thread [Next in Thread]