Two issues with opening binary files.
1) when I (accidentally?) open a binary executable file it often
kills my w98 X server. I get X errors like this just before the demise:
xemacs: X Error of failed request: BadDrawable (invalid Pixmap or Window paramete
r)
Major opcode of failed request: 64 (X_PolyPoint)
Resource id in failed request: 0x4c010005
Serial number of failed request: 36624
Current serial number in output stream: 38278
xemacs: X Error of failed request: BadLength (poly request too large or internal
Xlib length error)
Major opcode of failed request: 92 (X_LookupColor)
Serial number of failed request: 36625
Current serial number in output stream: 38278
So, opening binary files is bad, so I decided to write an
advice type thing to open the executable in hexl mode.
;; Open files that begin with 'ELF' in some other mode.
(defvar executable-pattern (concat "^" (regexp-opt (mapcar 'regexp-quote
'("\177ELF")) t)))
(defadvice set-auto-mode (around look-for-executables first activate)
(if (save-excursion
(goto-char (point-min))
(looking-at executable-pattern))
(hexl-mode)
ad-do-it))
This seemed to work fine until tar mode came along:
(defun tar-set-auto-mode ()
(interactive)
(if (and buffer-file-name
(string-match tar-regexp buffer-file-name))
(tar-mode)
(tar-real-set-auto-mode)))
(if (not (fboundp 'tar-real-normal-mode))
(fset 'tar-real-normal-mode (symbol-function 'normal-mode)))
(fset 'normal-mode 'tar-normal-mode)
(if (not (fboundp 'tar-real-set-auto-mode))
(fset 'tar-real-set-auto-mode (symbol-function 'set-auto-mode)))
(fset 'set-auto-mode 'tar-set-auto-mode)
Tar mode redefines set-auto-mode with different arguments
and was completely antisocial with my advice.
So, the questions are
1) Is there/Shouldn't there be a hook for catching binary files
and displaying them in a default 'binary' mode, like hexl.
2) shouldn't set-auto-mode have some sort of pre hook that
lets arbitrary hooks be tried until one of them returns true
eg 'run-hook-with-args-until-success'. Tar mode
would be a hook that intercepts files that end with .tar
-jeff
Show replies by date