From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Pierre Neidhardt Newsgroups: gmane.emacs.bugs Subject: bug#41784: 26.3; Narrow to prompt (narrow-to-defun fro M-x shell / comint) Date: Wed, 10 Jun 2020 10:51:06 +0200 Message-ID: <87sgf3e22t.fsf@ambrevar.xyz> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="55083"; mail-complaints-to="usenet@ciao.gmane.io" To: 41784@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 10 10:52:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jiwSw-000EIg-OB for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Jun 2020 10:52:10 +0200 Original-Received: from localhost ([::1]:40120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jiwSv-0005NE-Pd for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Jun 2020 04:52:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiwSp-0005Ms-1w for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 04:52:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jiwSo-0008Ss-N7 for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 04:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jiwSo-0005fr-Kw for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 04:52:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Pierre Neidhardt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Jun 2020 08:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41784 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.159177907521746 (code B ref -1); Wed, 10 Jun 2020 08:52:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Jun 2020 08:51:15 +0000 Original-Received: from localhost ([127.0.0.1]:33396 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jiwS3-0005ef-Gz for submit@debbugs.gnu.org; Wed, 10 Jun 2020 04:51:15 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:42260) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jiwS2-0005eY-6R for submit@debbugs.gnu.org; Wed, 10 Jun 2020 04:51:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiwS1-0005Fl-UC for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 04:51:13 -0400 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:55165) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jiwS0-0008P1-4v for bug-gnu-emacs@gnu.org; Wed, 10 Jun 2020 04:51:13 -0400 Original-Received: from bababa (lfbn-idf2-1-1315-147.w92-169.abo.wanadoo.fr [92.169.129.147]) (Authenticated sender: mail@ambrevar.xyz) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 55B79200002 for ; Wed, 10 Jun 2020 08:51:07 +0000 (UTC) Received-SPF: pass client-ip=217.70.178.232; envelope-from=mail@ambrevar.xyz; helo=relay12.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 04:51:08 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, FROM_SUSPICIOUS_NTLD=1, FROM_SUSPICIOUS_NTLD_FP=1, PDS_OTHER_BAD_TLD=1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181808 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi! I like the narrow-to-defun command and I miss it for comint-mode / M-x shel= l. Besides, I found it quite hard to reliably parse prompts, especially multiline prompt. So here are a bunch of functions that I think would make a great addition to upstream :) =2D-8<---------------cut here---------------start------------->8--- (defun ambrevar/shell-prompt-begin-position () ;; We need this convoluted function because `looking-at-p' does not work = on ;; multiline regexps _and_ `re-search-backward' skips the current line. (save-excursion (let ((old-point (point))) (max (save-excursion ;; Right result if not on prompt. (call-interactively #'comint-previous-prompt) (re-search-backward comint-prompt-regexp) (point)) (save-excursion ;; Right result if on first char after prompt. (re-search-backward comint-prompt-regexp) (point)) (save-excursion ;; Right result if on prompt. (call-interactively #'comint-next-prompt) (re-search-backward comint-prompt-regexp) (if (<=3D (point) old-point) (point) (point-min))))))) (defun ambrevar/shell-prompt-end-position () (save-excursion (goto-char (ambrevar/shell-prompt-begin-position)) (call-interactively #'comint-next-prompt) (point))) (defun ambrevar/shell-prompt () (buffer-substring-no-properties (ambrevar/shell-prompt-begin-position) (ambrevar/shell-prompt-end-position))) (defun ambrevar/shell-narrow-to-prompt () "Narrow buffer to prompt at point." (interactive) (let ((begin (ambrevar/shell-prompt-begin-position))) (narrow-to-region begin (save-excursion (goto-char (ambrevar/shell-prompt-end-position)) (call-interactively #'comint-next-prompt) (if (=3D begin (ambrevar/shell-prompt-begin-position)) (point-max) (ambrevar/shell-prompt-begin-position)))))) (define-key shell-mode-map (kbd "C-x n d") 'ambrevar/shell-narrow-to-prompt) =2D-8<---------------cut here---------------end--------------->8--- Cheers! =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAl7gnvoACgkQm9z0l6S7 zH8S9Qf8CIO1/uwh3+7HSSCMOgqkmfcaz6ldosxA8pYburqxvgle1oDAtKA2fQmH aST7QF+iAAHmlNuzR/C3VJF55V6hEKbgK8RFLHK5frC6HwwkvZ41t1CADD9dh9a9 1wPnjKqLK1TEANHSRAzsKGUllo948F2Y8GRNAhQUBr7m3V0UhAVqhQ/J7o4vpE64 CoFrLvsUTrFvUmj7eJP3PAApiPgSOnKdxyArvfwKcozeP5c3ffuyPpiqF2vKsu14 i2ccw6/Un4tfh3YPVPAJ23tvgASHhekq7au0FYkPsGeHPeadFNZysLhL9pPPxDPn UTVKoP4uQic8NYCJ2zg7WQpBBF6r5Q== =iYst -----END PGP SIGNATURE----- --=-=-=--