comparison lisp/hexl.el @ 8222:e03e94b14ba4

(hexl-maybe-dehexlify-buffer): New function. (hexl-mode): Add it to change-major-mode-hook. (hexl-mode-exit): Remove kludge for mode-line update. (hexlify-buffer): Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Tue, 12 Jul 1994 07:25:31 +0000
parents 8a2bc1679b10
children 4bbe5e8e59bb
comparison
equal deleted inserted replaced
8221:0b9e18f9b085 8222:e03e94b14ba4
169 169
170 (make-local-variable 'write-contents-hooks) 170 (make-local-variable 'write-contents-hooks)
171 (add-hook 'write-contents-hooks 'hexl-save-buffer) 171 (add-hook 'write-contents-hooks 'hexl-save-buffer)
172 172
173 (make-local-variable 'hexl-max-address) 173 (make-local-variable 'hexl-max-address)
174
175 (make-local-variable 'change-major-mode-hook)
176 (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer)
174 177
175 (let ((modified (buffer-modified-p)) 178 (let ((modified (buffer-modified-p))
176 (inhibit-read-only t) 179 (inhibit-read-only t)
177 (original-point (1- (point)))) 180 (original-point (1- (point))))
178 (if (not (or (eq arg 1) (not arg))) 181 (if (not (or (eq arg 1) (not arg)))
239 (set-buffer-modified-p modified) 242 (set-buffer-modified-p modified)
240 (goto-char original-point))) 243 (goto-char original-point)))
241 (setq mode-name hexl-mode-old-mode-name) 244 (setq mode-name hexl-mode-old-mode-name)
242 (use-local-map hexl-mode-old-local-map) 245 (use-local-map hexl-mode-old-local-map)
243 (setq major-mode hexl-mode-old-major-mode) 246 (setq major-mode hexl-mode-old-major-mode)
244 ;; Kludge to update mode-line 247 (force-mode-line-update))
245 (switch-to-buffer (current-buffer)) 248
246 ) 249 (defun hexl-maybe-dehexlify-buffer ()
250 "Convert a hexl format buffer to binary.
251 Ask the user for confirmation."
252 (if (y-or-n-p "Convert contents back to binary format? ")
253 (let ((modified (buffer-modified-p))
254 (inhibit-read-only t)
255 (original-point (1+ (hexl-current-address))))
256 (dehexlify-buffer)
257 (remove-hook 'write-contents-hook 'hexl-save-buffer)
258 (set-buffer-modified-p modified)
259 (goto-char original-point))))
247 260
248 (defun hexl-current-address () 261 (defun hexl-current-address ()
249 "Return current hexl-address." 262 "Return current hexl-address."
250 (interactive) 263 (interactive)
251 (let ((current-column (- (% (point) 68) 11)) 264 (let ((current-column (- (% (point) 68) 11))
496 509
497 ;00000000: 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789ABCDEF 510 ;00000000: 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789ABCDEF
498 511
499 ;;;###autoload 512 ;;;###autoload
500 (defun hexlify-buffer () 513 (defun hexlify-buffer ()
501 "Convert a binary buffer to hexl format" 514 "Convert a binary buffer to hexl format."
502 (interactive) 515 (interactive)
503 (let ((binary-process-output nil) ; for Ms-Dos 516 (let ((binary-process-output nil) ; for Ms-Dos
504 (binary-process-input t)) 517 (binary-process-input t))
505 (shell-command-on-region (point-min) (point-max) hexlify-command t))) 518 (shell-command-on-region (point-min) (point-max) hexlify-command t)))
506 519