GNU bug report logs -
#20723
24.4; narrow-to-line
Previous Next
Reported by: Ed Avis <eda <at> waniasset.com>
Date: Tue, 2 Jun 2015 17:01:03 UTC
Severity: wishlist
Tags: wontfix
Found in version 24.4
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #14 received at 20723 <at> debbugs.gnu.org (full text, mbox):
Ed Avis <eda <at> 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
This bug report was last modified 3 years and 116 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.