* eshell prompt function error
@ 2012-10-20 13:48 Guido Van Hoecke
2012-10-22 11:42 ` Doug Lewan
0 siblings, 1 reply; 3+ messages in thread
From: Guido Van Hoecke @ 2012-10-20 13:48 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I am not very proficient in lisp, so I would like some advise.
I like my eshell prompt of the form
2012-10-20 15:21 ~/dir/subdir
$
I use following function gratefully based upon code in
http://www.northbound-train.com/emacs/em-joc.el
(setq eshell-prompt-function
(lambda ()
(let ((prompt (eshell/pwd))
(now (format-time-string "\n%Y-%m-%d %H:%M " (current-time)))
(home-dir (expand-file-name "~")))
;; get rid of the nasty backslashes
(while (string-match "\\\\" home-dir)
(setq home-dir (replace-match "/" nil t home-dir)))
;; match home-dir at the begining of the line
;; be careful not to match `/users/foo.old' if $HOME is `/users/foo'
(if (string-match
(concat "^\\(" home-dir "\\)\\(/.*\\)?$")
prompt)
(setq prompt (replace-match
(if (and (match-string 2))
"~\\2"
"~")
nil
nil
prompt
0)))
;; return the prompt
;; -tack on \n$ or \n# depending on user id
(concat now prompt
(if (= (user-uid) 0) "\n# " "\n$ ")))))
Works fine 99,99% of the time
I also want to clear my eshell buffer from time to time and copied
(thank you oh original author) following method:
(defun eshell/clear ()
"04Dec2001 - sailor, to clear the eshell buffer."
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)))
Can somebody explain why my prompt function does not work anymore after
having issued the clear command?
It prints following text in the eshell buffer and no longer shows a
prompt:
Args out of range: 13, 38
When entering a command in this promptless buffer, it does work and
shows the prompt after executing the command.
I'd like to know what causes this and how to avoid it.
Any one?
Thanks in advance,
Guido
--
La-dee-dee, la-dee-dah.
http://vanhoecke.org ... and go2 places!
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: eshell prompt function error
2012-10-20 13:48 eshell prompt function error Guido Van Hoecke
@ 2012-10-22 11:42 ` Doug Lewan
2012-10-22 16:44 ` Guido Van Hoecke
0 siblings, 1 reply; 3+ messages in thread
From: Doug Lewan @ 2012-10-22 11:42 UTC (permalink / raw)
To: Guido Van Hoecke, help-gnu-emacs@gnu.org
Guido,
I have no problems with this. Specifically, using eshell/clear like a shell command or via M-x both seem to work.
Could you provide an error case?
Thanks.
,Doug
> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
> Behalf Of Guido Van Hoecke
> Sent: Saturday, 2012 October 20 09:49
> To: help-gnu-emacs@gnu.org
> Subject: eshell prompt function error
>
> Hi,
>
> I am not very proficient in lisp, so I would like some advise.
>
> I like my eshell prompt of the form
>
> 2012-10-20 15:21 ~/dir/subdir
> $
>
> I use following function gratefully based upon code in
> http://www.northbound-train.com/emacs/em-joc.el
>
> (setq eshell-prompt-function
> (lambda ()
> (let ((prompt (eshell/pwd))
> (now (format-time-string "\n%Y-%m-%d %H:%M " (current-
> time)))
> (home-dir (expand-file-name "~")))
> ;; get rid of the nasty backslashes
> (while (string-match "\\\\" home-dir)
> (setq home-dir (replace-match "/" nil t home-dir)))
>
> ;; match home-dir at the begining of the line
> ;; be careful not to match `/users/foo.old' if $HOME is
> `/users/foo'
> (if (string-match
> (concat "^\\(" home-dir "\\)\\(/.*\\)?$")
> prompt)
>
> (setq prompt (replace-match
> (if (and (match-string 2))
> "~\\2"
> "~")
> nil
> nil
> prompt
> 0)))
>
> ;; return the prompt
> ;; -tack on \n$ or \n# depending on user id
> (concat now prompt
> (if (= (user-uid) 0) "\n# " "\n$ ")))))
>
> Works fine 99,99% of the time
>
> I also want to clear my eshell buffer from time to time and copied
> (thank you oh original author) following method:
>
> (defun eshell/clear ()
> "04Dec2001 - sailor, to clear the eshell buffer."
> (interactive)
> (let ((inhibit-read-only t))
> (erase-buffer)))
>
> Can somebody explain why my prompt function does not work anymore after
> having issued the clear command?
>
> It prints following text in the eshell buffer and no longer shows a
> prompt:
>
> Args out of range: 13, 38
>
> When entering a command in this promptless buffer, it does work and
> shows the prompt after executing the command.
>
> I'd like to know what causes this and how to avoid it.
>
> Any one?
>
> Thanks in advance,
>
>
> Guido
>
> --
> La-dee-dee, la-dee-dah.
>
> http://vanhoecke.org ... and go2 places!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: eshell prompt function error
2012-10-22 11:42 ` Doug Lewan
@ 2012-10-22 16:44 ` Guido Van Hoecke
0 siblings, 0 replies; 3+ messages in thread
From: Guido Van Hoecke @ 2012-10-22 16:44 UTC (permalink / raw)
To: Doug Lewan; +Cc: help-gnu-emacs@gnu.org
Doug,
There's probably some interaction with other parts of my initialisation
code.
Trying to build a pure test case, I started an emasc --no-init-file,
sourced the eshell.clear and the eshell-prompt-function and - as you
said - they work fine.
So I'll start hunting for some code that could interact.
Thanks for your reply.
Kind regards,
Guido
On 22 October 2012 13:42, Doug Lewan <dougl@shubertticketing.com> wrote:
> Guido,
>
> I have no problems with this. Specifically, using eshell/clear like a shell command or via M-x both seem to work.
>
> Could you provide an error case?
>
> Thanks.
>
> ,Doug
>
>
>> -----Original Message-----
>> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
>> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
>> Behalf Of Guido Van Hoecke
>> Sent: Saturday, 2012 October 20 09:49
>> To: help-gnu-emacs@gnu.org
>> Subject: eshell prompt function error
>>
>> Hi,
>>
>> I am not very proficient in lisp, so I would like some advise.
>>
>> I like my eshell prompt of the form
>>
>> 2012-10-20 15:21 ~/dir/subdir
>> $
>>
>> I use following function gratefully based upon code in
>> http://www.northbound-train.com/emacs/em-joc.el
>>
>> (setq eshell-prompt-function
>> (lambda ()
>> (let ((prompt (eshell/pwd))
>> (now (format-time-string "\n%Y-%m-%d %H:%M " (current-
>> time)))
>> (home-dir (expand-file-name "~")))
>> ;; get rid of the nasty backslashes
>> (while (string-match "\\\\" home-dir)
>> (setq home-dir (replace-match "/" nil t home-dir)))
>>
>> ;; match home-dir at the begining of the line
>> ;; be careful not to match `/users/foo.old' if $HOME is
>> `/users/foo'
>> (if (string-match
>> (concat "^\\(" home-dir "\\)\\(/.*\\)?$")
>> prompt)
>>
>> (setq prompt (replace-match
>> (if (and (match-string 2))
>> "~\\2"
>> "~")
>> nil
>> nil
>> prompt
>> 0)))
>>
>> ;; return the prompt
>> ;; -tack on \n$ or \n# depending on user id
>> (concat now prompt
>> (if (= (user-uid) 0) "\n# " "\n$ ")))))
>>
>> Works fine 99,99% of the time
>>
>> I also want to clear my eshell buffer from time to time and copied
>> (thank you oh original author) following method:
>>
>> (defun eshell/clear ()
>> "04Dec2001 - sailor, to clear the eshell buffer."
>> (interactive)
>> (let ((inhibit-read-only t))
>> (erase-buffer)))
>>
>> Can somebody explain why my prompt function does not work anymore after
>> having issued the clear command?
>>
>> It prints following text in the eshell buffer and no longer shows a
>> prompt:
>>
>> Args out of range: 13, 38
>>
>> When entering a command in this promptless buffer, it does work and
>> shows the prompt after executing the command.
>>
>> I'd like to know what causes this and how to avoid it.
>>
>> Any one?
>>
>> Thanks in advance,
>>
>>
>> Guido
>>
>> --
>> La-dee-dee, la-dee-dah.
>>
>> http://vanhoecke.org ... and go2 places!
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-10-22 16:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-20 13:48 eshell prompt function error Guido Van Hoecke
2012-10-22 11:42 ` Doug Lewan
2012-10-22 16:44 ` Guido Van Hoecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).