From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.bugs Subject: bug#20723: 24.4; narrow-to-line Date: Tue, 02 Jun 2015 20:32:44 +0200 Message-ID: <87bngyvu43.fsf@members.fsf.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1433270013 18372 80.91.229.3 (2 Jun 2015 18:33:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Jun 2015 18:33:33 +0000 (UTC) Cc: 20723@debbugs.gnu.org To: Ed Avis Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 02 20:33:22 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Yzqzv-00079B-KL for geb-bug-gnu-emacs@m.gmane.org; Tue, 02 Jun 2015 20:33:11 +0200 Original-Received: from localhost ([::1]:60415 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yzqzu-0006p8-Q3 for geb-bug-gnu-emacs@m.gmane.org; Tue, 02 Jun 2015 14:33:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yzqzr-0006ok-30 for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 14:33:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yzqzm-0008Sv-SM for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 14:33:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56175) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yzqzm-0008SZ-Ph for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 14:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Yzqzm-0008N9-4x for bug-gnu-emacs@gnu.org; Tue, 02 Jun 2015 14:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Nicolas Richard Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Jun 2015 18:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20723 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20723-submit@debbugs.gnu.org id=B20723.143326996832163 (code B ref 20723); Tue, 02 Jun 2015 18:33:02 +0000 Original-Received: (at 20723) by debbugs.gnu.org; 2 Jun 2015 18:32:48 +0000 Original-Received: from localhost ([127.0.0.1]:37917 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YzqzY-0008Mg-1F for submit@debbugs.gnu.org; Tue, 02 Jun 2015 14:32:48 -0400 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:61636) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YzqzV-0008MV-Ot for 20723@debbugs.gnu.org; Tue, 02 Jun 2015 14:32:46 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAPj1bVWkD4Xx/2dsb2JhbABbhEKsaAEBAQEBAQaZVQKCDAEBAQEBAYELhCMBAQR5EAgDISUPAQRJE4gt2nkBAQEBBgEBAQEehhmFKoUGB4QtBaYTj0sjg3o8MYJHAQEB Original-Received: from mathsrv4.ulb.ac.be (HELO localhost) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 02 Jun 2015 20:32:45 +0200 In-Reply-To: (Ed Avis's message of "Tue, 2 Jun 2015 16:55:27 +0000 (UTC)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:103508 Archived-At: Ed Avis 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