From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Robert L." Newsgroups: gmane.emacs.help Subject: Re: Function behaves differently when debugged Date: Mon, 21 May 2018 21:34:34 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Trace: blaine.gmane.org 1526938407 21553 195.159.176.226 (21 May 2018 21:33:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 21 May 2018 21:33:27 +0000 (UTC) User-Agent: XanaNews/1.18.1.6 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 21 23:33:23 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fKsQk-0005RM-Ko for geh-help-gnu-emacs@m.gmane.org; Mon, 21 May 2018 23:33:22 +0200 Original-Received: from localhost ([::1]:52541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fKsSp-00084t-Vc for geh-help-gnu-emacs@m.gmane.org; Mon, 21 May 2018 17:35:32 -0400 X-Received: by 2002:a1c:6c14:: with SMTP id h20-v6mr46922wmc.13.1526938477590; Mon, 21 May 2018 14:34:37 -0700 (PDT) Original-Path: usenet.stanford.edu!2-v6no9797003wml.0!news-out.google.com!o2-v6ni24255wmf.0!nntp.google.com!proxad.net!feeder1-2.proxad.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 56 Original-NNTP-Posting-Host: Ca5bwqpzRqfIaDYNPT/e9A.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.3 Original-Xref: usenet.stanford.edu gnu.emacs.help:222681 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116802 Archived-At: 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