aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-12-31 16:09:45 +0000
committerRichard M. Stallman1995-12-31 16:09:45 +0000
commit0e4889b213ba0d0c46ce338a1ba92a5e1826a04b (patch)
tree465abb5fdb0a6fb57f06af6f820a6e5871cfe438
parent91afecb383c1f8fd60b9a29400c9b3f52242ab21 (diff)
downloademacs-0e4889b213ba0d0c46ce338a1ba92a5e1826a04b.tar.gz
emacs-0e4889b213ba0d0c46ce338a1ba92a5e1826a04b.zip
(hexl-mode): Don't call kill-all-local-variables.
Save write-contents-hooks, require-final-newline, the syntax table. Use make-local-hook for change-major-mode-hook. (hexl-mode-exit): Restore those vars; remove our local hooks.
-rw-r--r--lisp/hexl.el37
1 files changed, 29 insertions, 8 deletions
diff --git a/lisp/hexl.el b/lisp/hexl.el
index 123d23e46d2..0af45a246f2 100644
--- a/lisp/hexl.el
+++ b/lisp/hexl.el
@@ -80,6 +80,9 @@ and \"-de\" when dehexlfying a buffer.")
80(defvar hexl-mode-old-local-map) 80(defvar hexl-mode-old-local-map)
81(defvar hexl-mode-old-mode-name) 81(defvar hexl-mode-old-mode-name)
82(defvar hexl-mode-old-major-mode) 82(defvar hexl-mode-old-major-mode)
83(defvar hexl-mode-old-write-contents-hooks)
84(defvar hexl-mode-old-require-final-newline)
85(defvar hexl-mode-old-syntax-table)
83 86
84;; routines 87;; routines
85 88
@@ -157,8 +160,10 @@ You can use \\[hexl-find-file] to visit a file in hexl-mode.
157\\[describe-bindings] for advanced commands." 160\\[describe-bindings] for advanced commands."
158 (interactive "p") 161 (interactive "p")
159 (if (eq major-mode 'hexl-mode) 162 (if (eq major-mode 'hexl-mode)
160 (error "You are already in hexl mode.") 163 (error "You are already in hexl mode")
161 (kill-all-local-variables) 164
165 ;; We do not turn off the old major mode; instead we just
166 ;; override most of it. That way, we can restore it perfectly.
162 (make-local-variable 'hexl-mode-old-local-map) 167 (make-local-variable 'hexl-mode-old-local-map)
163 (setq hexl-mode-old-local-map (current-local-map)) 168 (setq hexl-mode-old-local-map (current-local-map))
164 (use-local-map hexl-mode-map) 169 (use-local-map hexl-mode-map)
@@ -171,19 +176,28 @@ You can use \\[hexl-find-file] to visit a file in hexl-mode.
171 (setq hexl-mode-old-major-mode major-mode) 176 (setq hexl-mode-old-major-mode major-mode)
172 (setq major-mode 'hexl-mode) 177 (setq major-mode 'hexl-mode)
173 178
179 (make-local-variable 'hexl-mode-old-syntax-table)
180 (setq hexl-mode-old-syntax-table (syntax-table))
181 (set-syntax-table (standard-syntax-table))
182
183 (make-local-variable 'hexl-mode-old-write-contents-hooks)
184 (setq hexl-mode-old-write-contents-hooks write-contents-hooks)
174 (make-local-variable 'write-contents-hooks) 185 (make-local-variable 'write-contents-hooks)
175 (add-hook 'write-contents-hooks 'hexl-save-buffer) 186 (add-hook 'write-contents-hooks 'hexl-save-buffer)
176 187
188 (make-local-variable 'hexl-mode-old-require-final-newline)
189 (setq hexl-mode-old-require-final-newline require-final-newline)
190 (make-local-variable 'require-final-newline)
191 (setq require-final-newline nil)
192
193 ;; Add hooks to rehexlify or dehexlify on various events.
177 (make-local-hook 'after-revert-hook) 194 (make-local-hook 'after-revert-hook)
178 (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t) 195 (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t)
179 196
180 (make-local-variable 'hexl-max-address) 197 (make-local-hook 'change-major-mode-hook)
181 198 (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t)
182 (make-local-variable 'change-major-mode-hook)
183 (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer)
184 199
185 (make-local-variable 'require-final-newline) 200 (make-local-variable 'hexl-max-address)
186 (setq require-final-newline nil)
187 201
188 (let ((modified (buffer-modified-p)) 202 (let ((modified (buffer-modified-p))
189 (inhibit-read-only t) 203 (inhibit-read-only t)
@@ -257,8 +271,15 @@ With arg, don't unhexlify buffer."
257 (remove-hook 'write-contents-hook 'hexl-save-buffer) 271 (remove-hook 'write-contents-hook 'hexl-save-buffer)
258 (set-buffer-modified-p modified) 272 (set-buffer-modified-p modified)
259 (goto-char original-point))) 273 (goto-char original-point)))
274
275 (remove-hook 'after-revert-hook 'hexl-after-revert-hook t)
276 (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t)
277
278 (setq write-contents-hooks hexl-mode-old-write-contents-hooks)
279 (setq require-final-newline hexl-mode-old-require-final-newline)
260 (setq mode-name hexl-mode-old-mode-name) 280 (setq mode-name hexl-mode-old-mode-name)
261 (use-local-map hexl-mode-old-local-map) 281 (use-local-map hexl-mode-old-local-map)
282 (set-syntax-table hexl-mode-old-syntax-table)
262 (setq major-mode hexl-mode-old-major-mode) 283 (setq major-mode hexl-mode-old-major-mode)
263 (force-mode-line-update)) 284 (force-mode-line-update))
264 285