From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4MYcBRuTnmBxAQEAgWs5BA (envelope-from ) for ; Fri, 14 May 2021 17:11:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id SGK+ABuTnmDANgAAB5/wlQ (envelope-from ) for ; Fri, 14 May 2021 15:11:23 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 677212A7BB for ; Fri, 14 May 2021 17:11:22 +0200 (CEST) Received: from localhost ([::1]:40874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhZTE-0002je-IY for larch@yhetil.org; Fri, 14 May 2021 11:11:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhZRd-0001ml-1e for emacs-orgmode@gnu.org; Fri, 14 May 2021 11:09:41 -0400 Received: from ciao.gmane.io ([116.202.254.214]:51262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhZRb-0005g2-9x for emacs-orgmode@gnu.org; Fri, 14 May 2021 11:09:40 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lhZRX-0005FR-RL for emacs-orgmode@gnu.org; Fri, 14 May 2021 17:09:35 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin Subject: Re: [PATCH] org-refile.el: Fix the case of emtpy buffer name Date: Fri, 14 May 2021 22:09:30 +0700 Message-ID: References: <20210513182052.2798-1-doublequotation@gmail.com> <20210513182052.2798-2-doublequotation@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 In-Reply-To: <20210513182052.2798-2-doublequotation@gmail.com> Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.248, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1621005082; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fBhuhz0o1Jv23rfW6+U+myIaQH1hYH54u55ifrKN8hM=; b=PMouL+RZD402tjEGWHG8YLymCpw+4kQNhJT2Oaa9SyTU7qpNcyuf3KvgydWCob/cBO7gHF UMo6vo0G/n6e2J8y7rSoRcKNw6KQrSuoNNIyBxqq33QUQQYUQbFFXNIvcGdZTpfb97FatO 7U3pfQQtNZmwWZX4PmWTeCEDIW6ViQOW79g4Fi8Q947fxJlIfjlfitW20DpNE0wuj0wjhh dWzBhVNj0dKEcu0vhqPCAkHK0C4ja3xbDfskmXSuGCBqXUd3iCrDa2rORqHligdSWj+kvw vh9lEi+m6sLsH8Xm8NQME9wiR0EZt0B+fctj/pDX45Vsk4ss1A3T+1mkNGco9w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621005082; a=rsa-sha256; cv=none; b=Q11KR2AXT/z4wC3aKnVOAbzoM8gn8JZLP8Tr4TnfYkqV8UL8IyTr3fWxqkIG4B6bnxoOMv Qtk6PKSRXnLzoIO6ZT+3u8w7iUcKOLpcpPHjMoJ4DAKW+CDU2bxY0t98tOpzYUmGShjwDR BOPrc/qyP8UFcMeZhD0Pa8fKOa44LaRiS6/x5OJ+Wq6xIsfK4PPzKL7DvUcGc/ctEFblQO HzN94IAuy8Tj8fk+BEkqtT0ib+E2VA/nNH5gpTAtC1Cv2BJ393Yo8fFuyQUYR+KUX0v3Vd S43LTttYC8yeWqTBI8u4kH+1w0pNNwNaaJH8O83NyMvqHGygB8fY+KbcMDUh9g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -0.35 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 677212A7BB X-Spam-Score: -0.35 X-Migadu-Scanner: scn0.migadu.com X-TUID: sqbvFqzQJn9I In my opinion, patch is the minimal change that fixes particular workflow and can be committed in the current form. Commit message may be improved a bit. I have a question (mainly to maintainer) if another approach could lead to undesired effects, see below. I have noticed a couple of old issues that can be improved later since they may require more changes than allowed for "TINYCHANGE". On 14/05/2021 01:20, satotake wrote: > [PATCH] org-refile.el: Fix the case of emtpy buffer name Buffer not associated with a file may be more precise since "*scratch*" has name. > * lisp/org-refile.el (org-refile-get-targets): Ensure > arg of `file-name-non' and `file-truename' is non-nil. truncated function name Comments below a loosely related to the suggested patch. > --- a/lisp/org-refile.el > +++ b/lisp/org-refile.el > @@ -310,11 +310,13 @@ converted to a headline before refiling." > (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)) > + (push (list (and f (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)) Notice `file-truename' > + (push (list (and (buffer-file-name (buffer-base-buffer)) > + (file-truename (buffer-file-name (buffer-base-buffer)))) > + f nil nil) tgs)) > (org-with-wide-buffer > (goto-char (point-min)) > (setq org-outline-path-cache nil) > @@ -337,9 +339,10 @@ converted to a headline before refiling." > #'identity > (append > (pcase org-refile-use-outline-path > - (`file (list (file-name-nondirectory > - (buffer-file-name > - (buffer-base-buffer))))) > + (`file (list > + (and (buffer-file-name (buffer-base-buffer)) I hope, additional operation in the inner loop has minimal performance penalty. Additional variable may be introduced and initialized before the loop over headings. It may help to avoid discrepancy similar to `file-truename'. > + (file-name-nondirectory > + (buffer-file-name (buffer-base-buffer)))))) > (`full-file-path > (list (buffer-file-name > (buffer-base-buffer)))) Earlier patch, that added `file-truename' above, missed this point. At first I was surprised why this clause does not require modification. To maintainers: What are negative consequences of completely skipping of buffers that have no associated files? I mean not to add them to the list for iteration. I can anticipate some tests should be fixed but I do not think it is a problem. Anyway `org-goto' and `org-refile' do not work in such buffers (from my point of view, reaction to such issue should be saving content of buffer to some file since critical size of notes is achieved): On 14/05/2021 01:20, satotake wrote: > In addition to your point, I found that we cannot refile internally even with > > my patch. In other words, if we can cache and reuse it, error ("Please > indicate a target file in the refile path") is raised > when we select it as refile target. > Probably, we need to some additional fixations. > It may be good to filter `files' which does not have `buffer-file-name'. >> Have you tried org-capture? > Yes. Mostly I use org-capture, especially, for creating TODO tasks. > I sometimes start with fundamental-mode new buffer. > After writing some texts, I switch to org-mode and try to call refile. > I do not know why I do it by myself clearly but I tend to do it when I > do not have any clear goal for the file. Thank you for details. I think, it is a kind of valid workflow. Personally I would consider it unreliable however. I suppose, `org-default-notes-file' (default capture target) better suited for temporary notes since it minimizes risk of lost text in the case of failure. It requires to change habits a bit to call org-capture with simple template in advance.