Subject: Re: bug#20723: 24.4; narrow-to-line

From: Stefan Kangas <[email-masked]>
Date: Wed, 06 Nov 2019 03:05:17 +0100

Drew Adams <[email-masked]> writes:

>> It would be handy to have M-x narrow-to-line to narrow the buffer to
>> the line point is currently on.
>
> (defun narrow-to-line (&optional arg)
>   "Narrow to the text of the current line.
> A numeric prefix arg means move forward (backward if negative) that
> many lines, thus narrowing to a line other than the one point was
> originally in."
>   (interactive "P")
>   (setq arg  (if arg (prefix-numeric-value arg) 0))
>   (let ((inhibit-field-motion  t))
>     (save-excursion
>       (forward-line arg)
>       (narrow-to-region (line-beginning-position) (line-end-position)))))
>
> (defun mark-line (&optional arg)
>   "Put mark at end of line, point at beginning.
> A numeric prefix arg means move forward (backward if negative) that
> many lines, thus marking a line other than the one point was
> originally in."
>   (interactive "P")
>   (setq arg  (if arg (prefix-numeric-value arg) 0))
>   (let ((inhibit-field-motion  t))
>     (forward-line arg)
>     (push-mark nil t t)
>     (goto-char (line-end-position))))

I think the proposal to add these commands make sense, since there
seems to exist a user demand.  Would anyone object to including the
above commands in Emacs?

> The problem is what keys, if any, to bind them to by default.

I'd suggest that we bind narrow-to-line to 'C-x n l', and leave
mark-line unbound by default for now.

> Here are some existing commands that are similar:
> http://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html
> http://www.gnu.org/software/emacs/manual/html_node/emacs/Marking-Objects.html

Best regards,
Stefan Kangas