0
|
1 ;;!emacs
|
|
2 ;;
|
|
3 ;; FILE: hlvar.el
|
|
4 ;; SUMMARY: Permits use of Hyperbole variables in local variable lists.
|
|
5 ;; USAGE: GNU Emacs Lisp Library
|
|
6 ;; KEYWORDS: extensions, hypermedia
|
|
7 ;;
|
|
8 ;; AUTHOR: Bob Weiner
|
|
9 ;; ORG: Brown U.
|
|
10 ;;
|
|
11 ;; ORIG-DATE: 4-Nov-91 at 00:26:06
|
|
12 ;; LAST-MOD: 21-Jun-95 at 00:50:14 by Bob Weiner
|
|
13 ;;
|
|
14 ;; This file is part of Hyperbole.
|
|
15 ;; Available for use and distribution under the same terms as GNU Emacs.
|
|
16 ;;
|
|
17 ;; Copyright (C) 1985-1995, Free Software Foundation, Inc.
|
|
18 ;;
|
|
19 ;; This file is not part of GNU Emacs but the code here is a slight
|
|
20 ;; variant of that found in "files.el" from GNU Emacs.
|
|
21 ;;
|
|
22 ;; DESCRIPTION:
|
|
23 ;;
|
|
24 ;; Hyperbole uses the colon character extensively in its variable names.
|
|
25 ;; The standard GNU Emacs syntax for local variable setting does not allow
|
|
26 ;; the use of this character, even though it is a valid symbol name
|
|
27 ;; character. The code here is slightly modified to support local setting of
|
|
28 ;; variables with colons in their names.
|
|
29 ;;
|
|
30 ;; Where the standard code allows: var:val
|
|
31 ; This code requires one use: var: val (where var may include colons)
|
|
32 ;;
|
|
33 ;; So functionality is gained and none is lost, but a slight incompatibility
|
|
34 ;; in protocol is introduced.
|
|
35 ;;
|
|
36 ;; DESCRIP-END.
|
|
37
|
|
38 ;;; ************************************************************************
|
|
39 ;;; Public functions
|
|
40 ;;; ************************************************************************
|
|
41
|
|
42 (defun hack-local-variables (&optional force)
|
|
43 "Parse, and bind or evaluate as appropriate, any local variables
|
|
44 for current buffer."
|
|
45 (if (fboundp 'hack-local-variables-prop-line)
|
|
46 (hack-local-variables-prop-line))
|
|
47 ;; Look for "Local variables:" line in last page.
|
|
48 (save-excursion
|
|
49 (goto-char (point-max))
|
|
50 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
|
|
51 (let (local-start)
|
|
52 (if (let ((case-fold-search t)
|
|
53 (ignore nil))
|
|
54 (and (search-forward "Local Variables:" nil t)
|
|
55 (setq local-start (match-beginning 0))
|
|
56 (or (and (not (string-match "^19\\." emacs-version))
|
|
57 (not inhibit-local-variables))
|
|
58 force
|
|
59 (if (string-match "^19\\." emacs-version)
|
|
60 (cond ((eq enable-local-variables t) t)
|
|
61 ((eq enable-local-variables nil)
|
|
62 (setq ignore t))))
|
|
63 (if ignore
|
|
64 nil
|
|
65 (save-window-excursion
|
|
66 (switch-to-buffer (current-buffer))
|
|
67 (save-excursion
|
|
68 (beginning-of-line)
|
|
69 (set-window-start (selected-window) (point)))
|
|
70 (y-or-n-p
|
|
71 (format "Set local variables as specified at end of %s? "
|
|
72 (file-name-nondirectory
|
|
73 buffer-file-name))))))))
|
|
74 (let ((continue t)
|
|
75 prefix prefixlen suffix beg
|
|
76 (enable-local-eval
|
|
77 (if (boundp 'enable-local-eval) enable-local-eval)))
|
|
78 ;; The prefix is what comes before "local variables:" in its line.
|
|
79 ;; The suffix is what comes after "local variables:" in its line.
|
|
80 (skip-chars-forward " \t")
|
|
81 (or (eolp)
|
|
82 (setq suffix (buffer-substring (point)
|
|
83 (progn (end-of-line) (point)))))
|
|
84 (goto-char local-start)
|
|
85 (or (bolp)
|
|
86 (setq prefix
|
|
87 (buffer-substring (point)
|
|
88 (progn (beginning-of-line) (point)))))
|
|
89
|
|
90 (if prefix (setq prefixlen (length prefix)
|
|
91 prefix (regexp-quote prefix)))
|
|
92 (if suffix (setq suffix (concat (regexp-quote suffix) "$")))
|
|
93 (while continue
|
|
94 ;; Look at next local variable spec.
|
|
95 (if selective-display (re-search-forward "[\n\C-m]")
|
|
96 (forward-line 1))
|
|
97 ;; Skip the prefix, if any.
|
|
98 (if prefix
|
|
99 (if (looking-at prefix)
|
|
100 (forward-char prefixlen)
|
|
101 (error "Local variables entry is missing the prefix")))
|
|
102 ;; Find the variable name; strip whitespace.
|
|
103 (skip-chars-forward " \t")
|
|
104 (setq beg (point))
|
|
105 ;;
|
|
106 ;; Bob Weiner - changed here to allow colons in var names.
|
|
107 ;;
|
|
108 (skip-chars-forward "^ \t\n")
|
|
109 (skip-chars-backward ":")
|
|
110 (or (looking-at "[ \t]*:")
|
|
111 (error "(hack-local-variables): Missing colon in local variables entry"))
|
|
112 ;;
|
|
113 ;; Bob Weiner - end changes.
|
|
114 ;;
|
|
115 (let* ((str (buffer-substring beg (point)))
|
|
116 (var (read str))
|
|
117 val)
|
|
118 ;; Setting variable named "end" means end of list.
|
|
119 (if (string-equal (downcase str) "end")
|
|
120 (setq continue nil)
|
|
121 ;; Otherwise read the variable value.
|
|
122 (skip-chars-forward "^:")
|
|
123 (forward-char 1)
|
|
124 (setq val (read (current-buffer)))
|
|
125 (skip-chars-backward "\n")
|
|
126 (skip-chars-forward " \t")
|
|
127 (or (if suffix (looking-at suffix) (eolp))
|
|
128 (error "Local variables entry is terminated incorrectly"))
|
|
129 ;; Set the variable. "Variables" mode and eval are funny.
|
|
130 (if (fboundp 'hack-one-local-variable)
|
|
131 (hack-one-local-variable var val)
|
|
132 (cond ((eq var 'mode)
|
|
133 (funcall (intern (concat (downcase (symbol-name val))
|
|
134 "-mode"))))
|
|
135 ((eq var 'eval)
|
|
136 (if (string= (user-login-name) "root")
|
|
137 (message
|
|
138 "Ignoring `eval:' in file's local variables")
|
|
139 (eval val)))
|
|
140 (t (make-local-variable var)
|
|
141 (set var val))))))))))
|
|
142 (run-hooks 'hack-local-variables-hook)))
|
|
143
|
|
144 (provide 'hlvar)
|