bug#81516: 31.0.91; delete-file-local-variable(-prop-line) should delete "Local Variables" block (prop-line)
Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]> Thu, 30 Jul 2026 09:31:29 +0200
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
Eli Zaretskii <[email protected]> writes: >> From: Daniel Mendler <[email protected]> >> Cc: [email protected], [email protected], [email protected] >> Date: Thu, 30 Jul 2026 08:45:23 +0200 >> >> Eli Zaretskii <[email protected]> writes: >> >> >> > The patch looks OK to me, and indeed the most important aspect is to >> >> > remove this error. But I think it's also a good idea to remove the >> >> > overall block in `delete-file-local-variable(-prop-line)` when that >> >> > block becomes empty, as a matter of aesthetics. >> >> >> >> Granted, I'm not opposed to removing those, in addition to fixing the >> >> error. >> > >> > I've now installed my patch on the master branch. >> > >> > Should we close this bug, or does anyone want to work on removing the >> > local vars block and the prop line when they become empty? >> >> Thanks. I would like to see this change. Patch attached. > > Thanks. Could we please have tests for this, including in cases where > the prop line doesn't exist, or looks similar, but isn't a prop line? I have not found tests for file local variables. Are there any? I can write a bunch of basic tests but this will take a little more time. >> + ;; Delete empty prop-line. >> + (when (and (eq op 'delete) deleted (= beg end)) >> + (save-excursion >> + (delete-region >> + (progn >> + (goto-char beg) >> + (search-backward "-*-" (line-beginning-position)) >> + (point)) >> + (progn >> + (goto-char end) >> + (search-forward "-*-" (line-end-position)) >> + (point))) >> + (goto-char (line-beginning-position)) >> + (when (looking-at-p >> + (concat "^[ \t]*" (regexp-quote comment-start) >> + "[ \t]*" (regexp-quote comment-end) "[ \t]*$")) >> + (delete-region (point) (progn (forward-line 1) (point)))))) > > Is this robust enough? Wouldn't it be better to compare the entire > line with a fixed string ";; -*- -*-" ? I think so. Note that the first delete-region deletes only the empty -*- -*-, since there could be other text in the comment. After that we check if the line is empty, and in that case delete the entire line. Daniel