Bug#105889: dpkg-dev-el; Adding hooks to enter mode for Debian native logs
Package: dpkg-dev-el
Version: 1.42-1
Severity: wishlist
Background:
There is often a Local variables block in Debian changelogs
which debian-changelog-mode has been partially deleting in
recent versions.
The "mode: debian-changelog" line is still useful for Debian
native packages because the mode then gets invoked properly when
you edit an installed log file,
e.g. /usr/share/doc/debiandoc-sgml/changelog.gz (It's not named
changelog.Debian.gz so we can't autoload based on the name)
Discussion:
Following a discussion on debian-devel, I received two ideas
that would let debian-changelog-mode offer to delete the block
completely as it would no longer add any benefit:
Alan Shutko wrote:
> I'd put something in change-log-mode-hook which does the check, and
> sets major-mode appropriately. Unfortunately, interpreter-mode-alist
> is specific to files which start with #!.
Tollef Fog Heen wrote:
> Something like:
>
> (setq find-file-hooks
> (cons #'(lambda ()
> ;; Invoke proper modes when we don't know file extensions
> (cond ((looking-at "#!.*/perl") (perl-mode))
> ((looking-at "#!.*/tclsh") (tcl-mode))
> ((looking-at "#!.*/wish") (tcl-mode))))
> find-file-hooks))
>
> And add the proper regexp for Debian changelogs.
Solution:
If this function were added to /etc/emacs/site-start.d/50dpkg-dev-el.el :
(defun debian-changelog-find-file-hook ()
(if (looking-at
"\\S-+ +(\\([0-9]:\\)?[0-9][0-9a-zA-Z.+:]+\\(-\\([0-9a-zA-Z.+]+\\)\\)?) +[^\n]*")
(debian-changelog-mode)))
We could then use either of these hooks in the file as well:
(add-hook 'find-file-hooks 'debian-changelog-find-file-hook t)
(add-hook 'change-log-mode-hook 'debian-changelog-find-file-hook t)
Note that the name of the function assumes we'd pick the first
one, otherwise I'd change it.
The first hook catches the process early on. For _every_ file
loaded into Emacs, the first line is compared to the regexp and
if it matches debian-changelog-mode is entered.
The second hook assumes that change-log-mode will end up catching
the log file. After the mode is fully loaded, the hook checks
the first line of the file for a match against the regexp and
enters debian-changelog-mode if matched. The advantage is that
only log files will be checked, and not all files visited by
Emacs. The disadvantage is that change-log-mode might have setup
unwanted variables that are not undone before entering
debian-changelog-mode.
What do you think?
Peter
Reply to: