unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* 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

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).