all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Function behaves differently when debugged
@ 2018-05-14 22:34 Matthias Pfeifer
  0 siblings, 0 replies; 3+ messages in thread
From: Matthias Pfeifer @ 2018-05-14 22:34 UTC (permalink / raw)
  To: help-gnu-emacs

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.


Thanks for your help.


Matthias


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Function behaves differently when debugged
       [not found] <mailman.3.1526337298.20804.help-gnu-emacs@gnu.org>
@ 2018-05-15 14:48 ` Ralf Fassel
  2018-05-21 21:34 ` Robert L.
  1 sibling, 0 replies; 3+ messages in thread
From: Ralf Fassel @ 2018-05-15 14:48 UTC (permalink / raw)
  To: help-gnu-emacs

* Matthias Pfeifer <pfemat@web.de>
| 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

You could set the variable debug-on-error to t to see where the error
occurs and protect that function call by 'stringp'.

| Also I do not understand why my function behaves differently when my
| defun is debugged and when it run without debugging.

Probably because the current buffer query function does not return
'nil' when you are in the debugging console...

HTH
R'


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Function behaves differently when debugged
       [not found] <mailman.3.1526337298.20804.help-gnu-emacs@gnu.org>
  2018-05-15 14:48 ` Function behaves differently when debugged Ralf Fassel
@ 2018-05-21 21:34 ` Robert L.
  1 sibling, 0 replies; 3+ messages in thread
From: Robert L. @ 2018-05-21 21:34 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-21 21:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3.1526337298.20804.help-gnu-emacs@gnu.org>
2018-05-15 14:48 ` Function behaves differently when debugged Ralf Fassel
2018-05-21 21:34 ` Robert L.
2018-05-14 22:34 Matthias Pfeifer

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.