Glynn Clements wrote:
Edwin Steiner wrote:
> I fixed the following problem:
>
> When hexl-find-file opens a file for which
> font-locking is enabled (eg. a source code
> file), the buffer is font-locked before
> hexlify-buffer is called. This wastes time and
> can lead to inappropriate font-locking in the
> (then hexlified) buffer.
>
> My solution is:
[proposal snipped]
Sounds unnecessarily complex. I would have thought that it would be
better to have hexl-find-file either:
a) bind font-lock-auto-fontify and font-lock-mode-enable-list to nil,
b) bind find-file-hooks to nil, or
normal-mode would still be called unneccessarily.
c) bypass find-file altogether, in favour of e.g.
insert-file-contents
or even insert-file-contents literally.
To me, find-file seems too high level for something like hexl.
I thought about it again. (I also found a hexl-relevant
bug in lisp/process.el and submitted a patch.)
The most simple and elegant solution is rewriting
hexl-find-file to:
(defun hexl-find-file (filename)
"Edit file FILENAME in hexl-mode.
Switch to a buffer visiting file FILENAME, creating one if none exists."
(interactive "fFilename: ")
(let ((find-file-run-dired nil))
(switch-to-buffer (find-file-noselect filename nil t))
(if (not (eq major-mode 'hexl-mode))
(hexl-mode))))
It uses the RAWFILE argument of find-file-noselect.
No change to files.el is required, no additional
variable is required, and it achieves the desired
effect.
When hexl-find-file finds a file, which is already
visited by a live buffer, font-lock is not disabled.
I wonder, if it should be disabled (*before* the
buffer is hexlified, to save time. Deactivating
font-lock in a hexl-mode-hook will not avoid the
unneccessary font-locking.)
If font-locking is disabled by hexlify-buffer, it
will still be off, if you leave hexl-mode via
hexl-mode-exit. Would this be a problem?
If someone uses customized font-locking for hexl-mode
(as I do sometimes), how can the original font-locking
be restored after hexl-mode-exit?
I hope I didn't miss anything. If there is no
disagreement with this solution, I will submit a patch.
There are still problems with hexl-mode. I found that
revert-buffer doesn't always work, and sometimes XEmacs
crashes when switching hexl-mode on or off (on my
Win98 machine). If I have enough time I will try to
debug this.
-Edwin