emacs-devel
[Top][All Lists]
Advanced

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

etc/TODO: command to make a "Local Variables" section


From: Reiner Steib
Subject: etc/TODO: command to make a "Local Variables" section
Date: Mon, 17 Oct 2005 18:49:25 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Hi,

in etc/TODO we have:

,----[ etc/TODO ]
| * Important features:
| 
| [...]
| 
| ** Add a command to make a "Local Variables" section in the current buffer
|   and/or add a variable to the list.
`----

How about the following?

Upto now, it only adds a new section, but extending the function to
add a variable to an existing list can be done by using parts of
`hack-local-variables', AFAICS.

--8<---------------cut here---------------start------------->8---
(defun insert-local-variables (&optional formfeed mode coding variables)
  "Add a \"Local Variables\" section in the current buffer.

If FORMFEED, insert ^L before the \"Local Variables\" section.
If MODE, insert \"mode:\", if CODING, add \"coding:\".  VARIABLES
is a list of variables.  For all variables, the values in the
current buffer are used."
  (interactive
   (list (y-or-n-p "Insert page marker (formfeed)? ")
         (y-or-n-p "Insert mode? ")
         (y-or-n-p "Insert coding? ")
         (let ((var t) (lst nil))
           (while var
             (if (string=
                  ""
                  (setq var
                        (completing-read "Variable: " obarray 'boundp
                                         t nil nil nil)))
                 (setq var nil)
               (add-to-list 'lst (intern var))))
           lst)))
  (save-excursion
    (goto-char (point-max))
    (if (search-backward
         "Local Variables:"
         (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) t)
         t)
        (error "Buffer already has a \"Local Variables:\" list")
      (goto-char (point-max)))
    (when formfeed (insert "\n\f\n"))
    (set-mark (point))
    (insert "Local Variables:\n")
    (when mode
      (insert (format "mode: %s\n"
                      (replace-regexp-in-string
                       "-mode$" ""
                       (symbol-name major-mode)))))
    (when coding
      (insert (format "coding: %s\n"
                      (symbol-name buffer-file-coding-system))))
    (dolist (v variables)
      (insert (format "%s: %S\n" (symbol-name v) (symbol-value v))))
    (insert "End:\n")
    (comment-region (mark) (point))))
--8<---------------cut here---------------end--------------->8---

Bye, Reiner.

-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/





reply via email to

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