From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Joakim Hove Newsgroups: gmane.emacs.help Subject: Re: Force Reread of "local variables:" Date: Mon, 02 Feb 2004 16:06:50 +0100 Organization: University of Bergen Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <4yoeshh65x.fsf@skjellgran.ii.uib.no> References: <7f477f72.0401312101.256a733c@posting.google.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1075735517 362 80.91.224.253 (2 Feb 2004 15:25:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 2 Feb 2004 15:25:17 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 02 16:25:06 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AnfwY-0006Pv-00 for ; Mon, 02 Feb 2004 16:25:05 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Anfof-0007mr-PM for geh-help-gnu-emacs@m.gmane.org; Mon, 02 Feb 2004 10:16:49 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!uninett.no!nntp.uib.no!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 233 Original-NNTP-Posting-Host: skjellgran.ii.uib.no Original-X-Trace: toralf.uib.no 1075738140 78642 129.177.20.52 (2 Feb 2004 16:09:00 GMT) Original-X-Complaints-To: abuse@uib.no Original-NNTP-Posting-Date: 2 Feb 2004 16:09:00 GMT User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) Cancel-Lock: sha1:cq27TP0z2uHdGWa56TM8vLiTBuw= Original-Xref: shelby.stanford.edu gnu.emacs.help:120623 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:16569 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:16569 --=-=-= Hello, > Anyone have code that will force a re-read of a "local variables:" > sections in a file? I have attatched some code I use (and find quite useful) for manipulating buffer-variables: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=buffer-variables.el Content-Transfer-Encoding: 8bit ;; ;; This is free GPL software. Written by Joakim Hove . 12/09/2003 ;; (setq variable-separator "#################################################################") (setq local-variables-string "Local Variables:") (setq local-variables-endstring "End") (defun 3comment-start () (format "%s%s%s" comment-start comment-start comment-start)) (defun comment-end () (if (string= comment-end "") "***" comment-end)) (defun buffer-variables-defined () (end-of-buffer) (if (search-backward (format "%s %s %s" (3comment-start) local-variables-string (comment-end)) 0 t) t nil)) (defun buffer-variable-defined (variable) (save-excursion (beginning-of-buffer) (if (search-forward (format "%s %s:" (3comment-start) variable) (point-max) t) (point) nil))) (defun buffer-remove-local-variable (variable) (let ((pos (buffer-variable-defined variable))) (if pos (progn (goto-char pos) (beginning-of-line) (let ((p1 (point))) (next-line 1) (kill-region p1 (point))))))) (defun buffer-variables-insert-footer () (end-of-buffer) (let ((3comment-start (3comment-start)) (comment-end (comment-end))) (insert (format "%s%s%s\n" 3comment-start variable-separator comment-end)) (insert (format "%s %s %s\n" 3comment-start local-variables-string comment-end)) (insert (format "%s End: %s\n" 3comment-start comment-end)))) ;;(local-variables-defined)) (defun buffer-insert-local-variable (variable value) (end-of-buffer) (search-backward (format "%s %s: %s" (3comment-start) local-variables-endstring comment-end)) (newline 1) (previous-line 1) (insert (format "%s %s: %s %s" (3comment-start) variable value (comment-end)))) (defun buffer-variables-set () (interactive) (save-excursion (let* ((variable (completing-read "Variable to set: " buffer-variable-list)) (read-function) (value)) (dolist (var buffer-variable-list) (if (string-equal (car var) variable) (setq read-function (nth 1 var)))) (setq value (if read-function (funcall read-function) (read-from-minibuffer (format "Value for \"%s\" (include \" \" for string variables) : " variable)))) (if value (progn (set-buffer-variable-internal variable value) (message (format "%s = %s is now into effect" variable value))))))) (defun set-buffer-variable-internal (variable value) (if (not (buffer-variables-defined)) (buffer-variables-insert-footer)) (buffer-remove-local-variable variable) (buffer-insert-local-variable variable value) (read-buffer-variables)) (defun read-buffer-variables () (interactive) (hack-local-variables)) (defun buffer-variables-start () (goto-char (point-max)) (search-backward local-variables-string) (forward-line 1) (point)) (defun buffer-variables-end () (goto-char (point-max)) (search-backward local-variables-endstring) (forward-line 0) (point)) (defun buffer-variables-make-active-list () (if (buffer-variables-defined) (let* ((variables) (p1 (buffer-variables-start)) (p2 (buffer-variables-end)) (go (> p2 p1))) (goto-char p1) (while go (if variables (setq variables (cons (buffer-variables-get-variable-at-line) variables)) (setq variables (list (buffer-variables-get-variable-at-line)))) (forward-line 1) (setq go (< (point) p2))) variables) 'nil)) (defun buffer-variables-get-variable-at-line () (re-search-forward (concat " \\([^ :]+\\): \\(.+\\) " (regexp-quote "***") "$")) (cons (match-string-no-properties 1) (match-string-no-properties 2))) (defun test () (interactive) (message "Variabel-list = %s" (buffer-variables-make-active-list))) (defun buffer-variables-delete-headers () (goto-char (point-max)) (let ((search-string (concat (3comment-start) variable-separator (comment-end) "\n" (3comment-start) " " local-variables-string " " (comment-end))) (p1) (p2)) (if (search-backward search-string) (setq p1 (point)) (error "Could not find start of local variables section - bailing out")) (if (search-forward (concat (3comment-start) " " local-variables-endstring ": " (comment-end))) (progn (forward-line 1) (setq p2 (point)) (kill-region p1 p2) (message "Deleting empty local variables section")) (error "Could not find end of local variables section - bailing out")))) (defun buffer-variables-delete-variable-internal (variable last-variable) (goto-char (buffer-variable-defined variable)) (let ((p1 (save-excursion (forward-line 0) (point))) (p2 (save-excursion (forward-line 1) (point)))) (kill-region p1 p2)) (if last-variable (buffer-variables-delete-headers))) (defun buffer-variables-delete-variable () (interactive) (let* ((active-list (buffer-variables-make-active-list)) (variable (if active-list (completing-read "Variable to remove: " active-list) 'nil))) (if variable (buffer-variables-delete-variable-internal variable (= (length active-list) 1 ))))) (require 'my-buffer-variables (user-lisp-path "my-buffer-variables.el")) (provide 'buffer-variables) ;;;#################################################################*** ;;; Local Variables: *** ;;; template-list: (HTML) *** ;;; End: *** --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=my-buffer-variables.el Content-Transfer-Encoding: 8bit ;; ;; This is free GPL software. Written by Joakim Hove . 12/09/2003 ;; ;; ;; A list of variables - along with a pointer to a function designed ;; to read in a value for this particular variable. ;; (setq buffer-variable-list '(("buffer-local-TeX-cmd" read-local-TeX-cmd) ("mode" read-mode) ("TeX-master" read-TeX-master) ("template-list" read-template-list) ("LaTeX-slide-buffer" read-LaTeX-slide-buffer) ("latex-encoding" read-latex-encoding))) (defun read-local-TeX-cmd () (concat "\"" (completing-read "Value for \"buffer-local-TeX-cmd\": " '(("LaTeX" . nil) ("LaTeX PDF" . nil) ("pdfLaTeX +pp4" . nil) ("LaTeX + dvips" . nil))) "\"")) (defun read-TeX-master () (concat "\"" (read-file-name "TeX-master-file: ") "\"")) (defun read-mode () (completing-read "Mode for this buffer: " '(("latex-slide" . nil) ("lisp-interaction" . nil)))) (defun read-latex-encoding () (concat "\"" (completing-read "Encoding for this buffer: " '(("Portable" . nil) ("National" . nil))) "\"")) (provide 'my-buffer-variables) --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Please ask if you have questions. HTH - Joakim -- /--------------------------------------------------------------------\ / Joakim Hove / hove@bccs.no / (55 5) 84076 | \ | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 | | CMU | 5231 Paradis | \ Thormøhlensgt.55, 5020 Bergen. | 55 91 28 18 / \--------------------------------------------------------------------/ --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://mail.gnu.org/mailman/listinfo/help-gnu-emacs --=-=-=--