annotate lisp/hyperbole/hlvar.el @ 143:50e7fedfe353

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