unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20723: 24.4; narrow-to-line
@ 2015-06-02 16:55 Ed Avis
  2015-06-02 18:14 ` Drew Adams
  2015-06-02 18:32 ` Nicolas Richard
  0 siblings, 2 replies; 9+ messages in thread
From: Ed Avis @ 2015-06-02 16:55 UTC (permalink / raw)
  To: 20723

It would be handy to have M-x narrow-to-line to narrow the buffer to the
line point is currently on.







^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2015-06-02 16:55 bug#20723: 24.4; narrow-to-line Ed Avis
@ 2015-06-02 18:14 ` Drew Adams
  2015-06-02 18:22   ` Ed Avis
  2019-11-06  2:05   ` Stefan Kangas
  2015-06-02 18:32 ` Nicolas Richard
  1 sibling, 2 replies; 9+ messages in thread
From: Drew Adams @ 2015-06-02 18:14 UTC (permalink / raw)
  To: Ed Avis, 20723

> 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))))

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

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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2015-06-02 18:14 ` Drew Adams
@ 2015-06-02 18:22   ` Ed Avis
  2015-06-02 19:35     ` Drew Adams
  2019-11-06  2:05   ` Stefan Kangas
  1 sibling, 1 reply; 9+ messages in thread
From: Ed Avis @ 2015-06-02 18:22 UTC (permalink / raw)
  To: 20723

Thanks.  I was imagining that narrow-to-line would not be bound to any key
by default.  After all, even narrow-to-region comes with a warning that it is
for experts only.

-- 
Ed Avis <eda@waniasset.com>






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2015-06-02 16:55 bug#20723: 24.4; narrow-to-line Ed Avis
  2015-06-02 18:14 ` Drew Adams
@ 2015-06-02 18:32 ` Nicolas Richard
  1 sibling, 0 replies; 9+ messages in thread
From: Nicolas Richard @ 2015-06-02 18:32 UTC (permalink / raw)
  To: Ed Avis; +Cc: 20723

Ed Avis <eda@waniasset.com> writes:
> It would be handy to have M-x narrow-to-line to narrow the buffer to the
> line point is currently on.

I'll give my own experience : I wanted a similar command and first wrote
a naive command along the lines of :
  (narrow-to-region (point-at-bol)
                    (save-excursion
                      (forward-line 1)
                      (point)))
but then, when widening the view, the window-start is usually modified
and I found this annoying. What I now have in my .emacs is what follows.
It keeps track of window-start and resets it when widening. Not very
clean code, but it worked good enough for me until now.

(defvar-local yf/narrow-to-line--state nil)
(defun yf/narrow-to-line ()
  (interactive)
  (setq yf/narrow-to-line--state
        (list (selected-window) (window-start)))
  (narrow-to-region (point-at-bol)
                    (save-excursion
                      (forward-line 1)
                      (point)))
  (add-hook 'post-command-hook #'yf/unnarrow-to-line nil t))
(defun yf/unnarrow-to-line ()
  (when (and yf/narrow-to-line--state
             (not (buffer-narrowed-p)))
    (apply #'set-window-start yf/narrow-to-line--state)
    (setq yf/narrow-to-line--state nil)
    (remove-hook 'post-command-hook #'yf/unnarrow-to-line t)))
(bind-key "l" 'yf/narrow-to-line narrow-map)

FWIW, totally unrelated, but I also have the following :
(defun yf/narrow-to-window-view (printmsg)
  (interactive "p")
  (narrow-to-region (window-start)
                    (save-excursion
                      (goto-char (window-end nil t))
                      (when (not (pos-visible-in-window-p))
                        ;; Line is not fully visible.
                        (forward-visible-line -1))
                      (point)))
  (when printmsg
    (message "Narrowed to visible portion of buffer in current
    window.")))
(bind-key "v" 'yf/narrow-to-window-view narrow-map)

-- 
Nico





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2015-06-02 18:22   ` Ed Avis
@ 2015-06-02 19:35     ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2015-06-02 19:35 UTC (permalink / raw)
  To: Ed Avis, 20723

> Thanks.  I was imagining that narrow-to-line would not be bound to
> any key by default.  After all, even narrow-to-region comes with a warning
> that it is for experts only.

`narrow-to-region' is not for experts only.  It is disabled by default
because the thought is that if you don't expect it then you could get
confused, especially if you invoked it accidentally (e.g., by key).
But it nevertheless has a key binding by default.

I don't expect that `mark-line' is very useful.  But I can see
someone wanting to use something like `narrow-to-line' (especially
with very long lines).

(Of course, `C-a C-SPC C-e C-x n' does the same thing, except for
keeping the cursor where it was.)





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2015-06-02 18:14 ` Drew Adams
  2015-06-02 18:22   ` Ed Avis
@ 2019-11-06  2:05   ` Stefan Kangas
  2019-11-06 14:06     ` Drew Adams
  2022-01-29 17:05     ` Lars Ingebrigtsen
  1 sibling, 2 replies; 9+ messages in thread
From: Stefan Kangas @ 2019-11-06  2:05 UTC (permalink / raw)
  To: Drew Adams; +Cc: 20723, Ed Avis

Drew Adams <drew.adams@oracle.com> 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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2019-11-06  2:05   ` Stefan Kangas
@ 2019-11-06 14:06     ` Drew Adams
  2019-11-06 14:14       ` Stefan Kangas
  2022-01-29 17:05     ` Lars Ingebrigtsen
  1 sibling, 1 reply; 9+ messages in thread
From: Drew Adams @ 2019-11-06 14:06 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 20723, Ed Avis

> >> It would be handy to have M-x narrow-to-line to narrow the buffer to
> >> the line point is currently on.
> 
> 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.

I agree now with Ed Avis that we should _not_ bind
either command to a key by default.  Anyone who
uses them can bind them to keys.

These commands are not super-useful.  There is no
reason to sacrifice default keys to them.  It's
good to have such commands, but default keys
should be defined only when we know there's a lot
of clamor for them. ;-)






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2019-11-06 14:06     ` Drew Adams
@ 2019-11-06 14:14       ` Stefan Kangas
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Kangas @ 2019-11-06 14:14 UTC (permalink / raw)
  To: Drew Adams; +Cc: 20723, Ed Avis

Drew Adams <drew.adams@oracle.com> writes:

>> I'd suggest that we bind narrow-to-line to 'C-x n l', and leave
>> mark-line unbound by default for now.
>
> I agree now with Ed Avis that we should _not_ bind
> either command to a key by default.  Anyone who
> uses them can bind them to keys.
>
> These commands are not super-useful.  There is no
> reason to sacrifice default keys to them.  It's
> good to have such commands, but default keys
> should be defined only when we know there's a lot
> of clamor for them. ;-)

That's fine by me.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20723: 24.4; narrow-to-line
  2019-11-06  2:05   ` Stefan Kangas
  2019-11-06 14:06     ` Drew Adams
@ 2022-01-29 17:05     ` Lars Ingebrigtsen
  1 sibling, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-29 17:05 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 20723, Ed Avis

Stefan Kangas <stefan@marxist.se> writes:

> 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?

In my opinion, they aren't generally useful enough either as commands
(it's easier to just use the normal point movement and narrowing
commands) or in code (narrowing to a line in code isn't very common), so
I don't think it's worth adding these to Emacs, and I'm therefore
closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-01-29 17:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-02 16:55 bug#20723: 24.4; narrow-to-line Ed Avis
2015-06-02 18:14 ` Drew Adams
2015-06-02 18:22   ` Ed Avis
2015-06-02 19:35     ` Drew Adams
2019-11-06  2:05   ` Stefan Kangas
2019-11-06 14:06     ` Drew Adams
2019-11-06 14:14       ` Stefan Kangas
2022-01-29 17:05     ` Lars Ingebrigtsen
2015-06-02 18:32 ` Nicolas Richard

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).