all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Robert L." <No_spamming@noWhere_7073.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Function behaves differently when debugged
Date: Mon, 21 May 2018 21:34:34 +0000 (UTC)	[thread overview]
Message-ID: <pdve19$5ke$1@gioia.aioe.org> (raw)
In-Reply-To: mailman.3.1526337298.20804.help-gnu-emacs@gnu.org

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


  parent reply	other threads:[~2018-05-21 21:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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. [this message]
2018-05-14 22:34 Matthias Pfeifer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='pdve19$5ke$1@gioia.aioe.org' \
    --to=no_spamming@nowhere_7073.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.