bug#81516: 31.0.91; delete-file-local-variable(-prop-line) should delete "Local Variables" block (prop-line)

Eli Zaretskii <[email protected]> Thu, 30 Jul 2026 10:27:32 +0300
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> 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?

> +      ;; 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 ";; -*- -*-" ?