[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newbie tries to hack comint.el (help!)
From: |
bill |
Subject: |
Re: newbie tries to hack comint.el (help!) |
Date: |
Tue, 29 Jun 2004 17:36:03 -0000 |
User-agent: |
nn/6.6.5 |
In <877jujt2bx.fsf@tc-1-100.kawasaki.gol.ne.jp> Miles Bader <miles@gnu.org>
writes:
>bill <please_post@nomail.edu> writes:
>> One thing that this function must do, but I have not been able to
>> figure out is how to to move the point to the beginning of the line
>> of the immediately preceding shell input. I've been able to handle
>> simple cases, but not tricky ones like:
>>
>> myhost:~/some/dir$ foo \
>>> bar \
>>> baz_
>>
>> where '_' immediately after 'baz' indicates the location of the
>> point at the time I want to move it to the beginning of the line
>> beginning with "myhost".
>Probably you're best bet is to write your own regexp that matches your
>own prompt, but not shell `subprompts' like ">" -- or perhaps a regexp
>that only matches prompts you want to avoid -- and then scan back
>through what comint things are prompts, until you find something that
>matches (or doesn't match).
>For instance:
> ;; Regexp matching prompts that `foo-beginning-of-previous-important-prompt'
> ;; should avoid.
> (defvar foo-avoid-prompt-regexp "^> *$")
> ;; Move to the beginning of the previous comint prompt that doesn't match
> ;; `foo-avoid-prompt-regexp'.
> (defun foo-beginning-of-previous-important-prompt ()
> (interactive)
> (while (and (comint-previous-prompt)
> (let ((prompt-end-pos (point)))
> (forward-line 0) ; move to true beginning-of-line
> (string-match foo-avoid-prompt-regexp
> (buffer-substring (point) prompt-end-pos))))))
>seems to work for your current example.
Good idea; it works like a charm. Well, almost: I had to give an
argument of 1 to comint-previous-prompt (actually, I'm surprised
your code worked at all, unless the code you posted was not a
faithful cut-and-paste of the code you tested).
Many thanks.
-bill