emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: satotake <doublequotation@gmail.com>
To: bzg@gnu.org
Cc: satotake <doublequotation@gmail.com>, emacs-orgmode@gnu.org
Subject: [PATCH] org-refile.el: Fix the case of *scratch* buffer
Date: Sat, 15 May 2021 19:38:39 +0900	[thread overview]
Message-ID: <20210515103839.8574-2-doublequotation@gmail.com> (raw)
In-Reply-To: <20210515103839.8574-1-doublequotation@gmail.com>

* lisp/org-refile.el (org-refile-get-targets): Ensure
arg of `file-name-nondirectory' and `file-truename' is non-nil.

If you set `org-refile-use-outline-path' `file' or `full-file-path',
and call `org-refile' in the buffer before visiting file,
errors are raised at these point. To fix them,
check if they are nil or not.

TINYCHANGE
---
 lisp/org-refile.el | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/lisp/org-refile.el b/lisp/org-refile.el
index 24a1bde51..01a0a6f7f 100644
--- a/lisp/org-refile.el
+++ b/lisp/org-refile.el
@@ -267,7 +267,7 @@ converted to a headline before refiling."
   (let ((case-fold-search nil)
 	;; otherwise org confuses "TODO" as a kw and "Todo" as a word
 	(entries (or org-refile-targets '((nil . (:level . 1)))))
-	targets tgs files desc descre)
+	targets tgs files desc descre tg-base)
     (message "Getting targets...")
     (with-current-buffer (or default-buffer (current-buffer))
       (dolist (entry entries)
@@ -309,12 +309,17 @@ converted to a headline before refiling."
 	       (when (bufferp f)
 		 (setq f (buffer-file-name (buffer-base-buffer f))))
 	       (setq f (and f (expand-file-name f)))
-	       (when (eq org-refile-use-outline-path 'file)
-		 (push (list (file-name-nondirectory f) f nil nil) tgs))
-	       (when (eq org-refile-use-outline-path 'buffer-name)
-		 (push (list (buffer-name (buffer-base-buffer)) f nil nil) tgs))
-	       (when (eq org-refile-use-outline-path 'full-file-path)
-		 (push (list (file-truename (buffer-file-name (buffer-base-buffer))) f nil nil) tgs))
+               (setq tg-base
+                     (pcase org-refile-use-outline-path
+                       (`file (and f (file-name-nondirectory f)))
+                       (`full-file-path
+                        (and (buffer-file-name (buffer-base-buffer))
+                             (file-truename (buffer-file-name (buffer-base-buffer)))))
+                       (`buffer-name (buffer-name (buffer-base-buffer)))
+                       (_ nil)))
+               (when (member org-refile-use-outline-path
+                             '(file full-file-path buffer-name))
+                 (push (list tg-base f nil nil) tgs))
 	       (org-with-wide-buffer
 		(goto-char (point-min))
 		(setq org-outline-path-cache nil)
@@ -336,17 +341,10 @@ converted to a headline before refiling."
 			       (mapconcat
 				#'identity
 				(append
-				 (pcase org-refile-use-outline-path
-				   (`file (list (file-name-nondirectory
-						 (buffer-file-name
-						  (buffer-base-buffer)))))
-				   (`full-file-path
-				    (list (buffer-file-name
-					   (buffer-base-buffer))))
-				   (`buffer-name
-				    (list (buffer-name
-					   (buffer-base-buffer))))
-				   (_ nil))
+                                 (if (member org-refile-use-outline-path
+                                             '(file full-file-path buffer-name))
+                                     (list tg-base)
+                                   nil)
 				 (mapcar (lambda (s) (replace-regexp-in-string
 						      "/" "\\/" s nil t))
 					 (org-get-outline-path t t)))
-- 
2.30.0



      reply	other threads:[~2021-05-15 10:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-09 14:47 org-refile.el: Fix the case of emtpy buffer name satotake
2021-05-09 14:47 ` [PATCH] " satotake
2021-05-09 15:55   ` satotake
2021-05-09 15:55     ` [PATCH 2/2] org-refile.el: Fix test case satotake
2021-05-09 16:05     ` satotake
2021-05-11 11:45       ` Maxim Nikulin
2021-05-13 18:20         ` org-refile.el: Fix test case (Squashed) satotake
2021-05-13 18:20           ` [PATCH] org-refile.el: Fix the case of emtpy buffer name satotake
2021-05-14 15:09             ` Maxim Nikulin
2021-05-15  8:20             ` Bastien
2021-05-15 10:38               ` satotake
2021-05-15 10:38                 ` satotake [this message]

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=20210515103839.8574-2-doublequotation@gmail.com \
    --to=doublequotation@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] org-refile.el: Fix the case of *scratch* buffer' \
    /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

Code repositories for project(s) associated with this inbox:

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

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