Function: hack-local-variables-prop-line
hack-local-variables-prop-line is a byte-compiled function defined in
files.el.gz.
Signature
(hack-local-variables-prop-line &optional HANDLE-MODE)
Documentation
Return local variables specified in the -*- line.
Usually returns an alist of elements (VAR . VAL), where VAR is a
variable and VAL is the specified value. Ignores any
specification for coding:, and sometimes for mode (which
should have already been handled by set-auto-coding and
set-auto-mode, respectively). Return nil if the -*- line is
malformed.
If HANDLE-MODE is nil, we return the alist of all the local
variables in the line except coding as described above. If it
is neither nil nor t, we do the same, except that any settings of
mode and coding are ignored. If HANDLE-MODE is t, we ignore
all settings in the line except for mode, which (if present) we
return as the symbol specifying the mode.
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun hack-local-variables-prop-line (&optional handle-mode)
"Return local variables specified in the -*- line.
Usually returns an alist of elements (VAR . VAL), where VAR is a
variable and VAL is the specified value. Ignores any
specification for `coding:', and sometimes for `mode' (which
should have already been handled by `set-auto-coding' and
`set-auto-mode', respectively). Return nil if the -*- line is
malformed.
If HANDLE-MODE is nil, we return the alist of all the local
variables in the line except `coding' as described above. If it
is neither nil nor t, we do the same, except that any settings of
`mode' and `coding' are ignored. If HANDLE-MODE is t, we ignore
all settings in the line except for `mode', which \(if present) we
return as the symbol specifying the mode."
(catch 'malformed-line
(save-excursion
(goto-char (point-min))
(let ((end (set-auto-mode-1))
result)
(cond ((not end)
nil)
((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
;; Simple form: "-*- MODENAME -*-".
(if (eq handle-mode t)
(intern (concat (match-string 1) "-mode"))))
(t
;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
;; (last ";" is optional).
;; If HANDLE-MODE is t, just check for `mode'.
;; Otherwise, parse the -*- line into the RESULT alist.
(while (not (or (and (eq handle-mode t) result)
(>= (point) end)))
(unless (looking-at hack-local-variable-regexp)
(message "Malformed mode-line: %S in buffer %S"
(buffer-substring-no-properties (point) end) (buffer-name))
(throw 'malformed-line nil))
(goto-char (match-end 0))
;; There used to be a downcase here,
;; but the manual didn't say so,
;; and people want to set var names that aren't all lc.
(let* ((key (intern (match-string 1)))
(val (save-restriction
(narrow-to-region (point) end)
;; As a defensive measure, we do not allow
;; circular data in the file-local data.
(let ((read-circle nil))
(read (current-buffer)))))
;; It is traditional to ignore
;; case when checking for `mode' in set-auto-mode,
;; so we must do that here as well.
;; That is inconsistent, but we're stuck with it.
;; The same can be said for `coding' in set-auto-coding.
(keyname (downcase (symbol-name key))))
(cond
((eq handle-mode t)
(and (equal keyname "mode")
(setq result
(intern (concat (downcase (symbol-name val))
"-mode")))))
((equal keyname "coding"))
(t
(when (or (not handle-mode)
(not (equal keyname "mode")))
(condition-case nil
(push (cons (cond ((eq key 'eval) 'eval)
;; Downcase "Mode:".
((equal keyname "mode") 'mode)
(t (indirect-variable key)))
val)
result)
(error nil)))))
(skip-chars-forward " \t;")))
result))))))