[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Function behaves differently when debugged
From: |
Robert L. |
Subject: |
Re: Function behaves differently when debugged |
Date: |
Mon, 21 May 2018 21:34:34 +0000 (UTC) |
User-agent: |
XanaNews/1.18.1.6 |
On 5/14/2018, Matthias Pfeifer wrote:
> Hi everybody,
>
> I have this function
>
> (defun mp-ibuffer-show-file-path ()
> (interactive)
> (let ((buf (ibuffer-current-buffer))
> (lsoutput nil))
> (if (not (null buf))
> (when (file-exists-p (buffer-file-name buf))
> (with-temp-buffer
> (let* ((filename (buffer-file-name buf))
> (file-directory (file-name-directory filename))
> (just-filename (file-name-nondirectory filename)))
> (setq lsoutput file-directory))))
> (setq lsoutput "Buffer is not backed by a file"))
> (message lsoutput)))
>
> I bind it to some key in ibuffer-mode. it should print the path to a
> buffer's file. When point is on a line of a buffer that is not backed by a
> file (eg Messages) then i get this output:
>
> wrong type argument: strinp, nil
>
> However when I instantiated my defun for debugging and do the same again I
> get
>
> "Buffer is not backed by a file"
>
> The second behavior is actually what i had expected when i was writing the
> function. The first behavior is a bit unexpected. Also I do not understand
> why my function behaves differently when my defun is debugged and when it
> run without debugging.
Untested.
(defun mp-ibuffer-show-file-path ()
(interactive)
(let ((buf (ibuffer-current-buffer))
(lsoutput "Buffer is not backed by a file"))
(when buf
(let ((filename (buffer-file-name buf)))
(when (and filename (file-exists-p filename))
(with-temp-buffer
(let* ((file-directory (file-name-directory filename))
(just-filename (file-name-nondirectory filename)))
(setq lsoutput file-directory))))))
(message lsoutput)))
--
The report card by the American Society of Civil Engineers showed the national
infrastructure a single grade above failure, a step from declining to the point
where everyday things simply stop working the way people expect them to.
http://archive.org/details/nolies