GNU bug report logs -
#41784
26.3; Narrow to prompt (narrow-to-defun fro M-x shell / comint)
Previous Next
Reported by: Pierre Neidhardt <mail <at> ambrevar.xyz>
Date: Wed, 10 Jun 2020 08:52:02 UTC
Severity: normal
Tags: fixed
Found in version 26.3
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41784 in the body.
You can then email your comments to 41784 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41784
; Package
emacs
.
(Wed, 10 Jun 2020 08:52:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Pierre Neidhardt <mail <at> ambrevar.xyz>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 10 Jun 2020 08:52:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi!
I like the narrow-to-defun command and I miss it for comint-mode / M-x shell.
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 :)
--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 (<= (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 (= 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)
--8<---------------cut here---------------end--------------->8---
Cheers!
--
Pierre Neidhardt
https://ambrevar.xyz/
[signature.asc (application/pgp-signature, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41784
; Package
emacs
.
(Sat, 17 Oct 2020 11:18:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 41784 <at> debbugs.gnu.org (full text, mbox):
Pierre Neidhardt <mail <at> ambrevar.xyz> writes:
> I like the narrow-to-defun command and I miss it for comint-mode / M-x shell.
> Besides, I found it quite hard to reliably parse prompts, especially
> multiline prompt.
Looks good to me, so I've added the functions to Emacs 28 (with some
minor changes).
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 17 Oct 2020 11:18:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
41784 <at> debbugs.gnu.org and Pierre Neidhardt <mail <at> ambrevar.xyz>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 17 Oct 2020 11:18:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#41784
; Package
emacs
.
(Sat, 17 Oct 2020 12:10:01 GMT)
Full text and
rfc822 format available.
Message #15 received at 41784 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thanks a lot!
--
Pierre Neidhardt
https://ambrevar.xyz/
[signature.asc (application/pgp-signature, inline)]
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 14 Nov 2020 12:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 161 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.