Function: dcl-save-local-variable
dcl-save-local-variable is a byte-compiled function defined in
dcl-mode.el.gz.
Signature
(dcl-save-local-variable VAR &optional DEF-PREFIX DEF-SUFFIX)
Documentation
Save a variable in a Local Variables list.
Set or update the value of VAR in the current buffers
Local Variables: list.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/dcl-mode.el.gz
;;; *** Save options ********************************************************
;;;-------------------------------------------------------------------------
(defun dcl-save-local-variable (var &optional def-prefix def-suffix)
"Save a variable in a `Local Variables' list.
Set or update the value of VAR in the current buffers
`Local Variables:' list."
;; Look for "Local variables:" line in last page.
(save-excursion
(goto-char (point-max))
(search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
(if (let ((case-fold-search t))
(search-forward "Local Variables:" nil t))
(let ((continue t)
prefix prefixlen suffix beg
prefix-string suffix-string)
;; The prefix is what comes before "local variables:" in its line.
;; The suffix is what comes after "local variables:" in its line.
(skip-chars-forward " \t")
(or (eolp)
(setq suffix-string (buffer-substring (point)
(line-end-position))))
(goto-char (match-beginning 0))
(or (bolp)
(setq prefix-string
(buffer-substring (point)
(progn (beginning-of-line) (point)))))
(if prefix-string (setq prefixlen (length prefix-string)
prefix (regexp-quote prefix-string)))
(if suffix-string (setq suffix (concat (regexp-quote suffix-string)
"$")))
(while continue
;; Look at next local variable spec.
(if selective-display (re-search-forward "[\n\C-m]")
(forward-line 1))
;; Skip the prefix, if any.
(if prefix
(if (looking-at prefix)
(forward-char prefixlen)
(error "Local variables entry is missing the prefix")))
;; Find the variable name; strip whitespace.
(skip-chars-forward " \t")
(setq beg (point))
(skip-chars-forward "^:\n")
(if (eolp) (error "Missing colon in local variables entry"))
(skip-chars-backward " \t")
(let* ((str (buffer-substring beg (point)))
(found-var (read str)))
;; Setting variable named "end" means end of list.
(if (string-equal (downcase str) "end")
(progn
;; Not found. Insert a new entry before this line
(setq continue nil)
(beginning-of-line)
(insert (concat prefix-string (symbol-name var) ": "
(prin1-to-string (symbol-value var)) " "
suffix-string "\n")))
;; Is it the variable we are looking for?
(if (eq var found-var)
(progn
;; Found it: delete the variable value and insert the
;; new value.
(setq continue nil)
(skip-chars-forward "^:")
(forward-char 1)
(delete-region (point) (progn (read (current-buffer))
(point)))
(insert " ")
(prin1 (symbol-value var) (current-buffer))
(skip-chars-backward "\n")
(skip-chars-forward " \t")
(or (if suffix (looking-at suffix) (eolp))
(error
"Local variables entry is terminated incorrectly")))
(end-of-line))))))
;; Did not find "Local variables:"
(goto-char (point-max))
(if (not (bolp))
(insert "\n"))
;; If def- parameter not set, use comment- if set. In that case, make
;; sure there is a space in a suitable position
(let ((def-prefix
(cond
(def-prefix
def-prefix)
(comment-start
(if (or (equal comment-start "")
(string-match "[ \t]$" comment-start))
comment-start
(concat comment-start " ")))))
(def-suffix
(cond
(def-suffix
def-suffix)
(comment-end
(if (or (equal comment-end "")
(string-match "^[ \t]" comment-end))
comment-end
(concat " " comment-end))))))
(insert (concat def-prefix "Local variables:" def-suffix "\n"))
(insert (concat def-prefix (symbol-name var) ": "
(prin1-to-string (symbol-value var)) def-suffix "\n"))
(insert (concat def-prefix "end:" def-suffix)))
)))