From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nathan Neff Subject: Re: org-refile-target-verify-function - use inherited tag & todo Date: Fri, 1 Nov 2019 19:47:18 -0500 Message-ID: References: <87h83tokxy.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000004e3df0596526d61" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:46621) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iQhZl-0007OW-PM for emacs-orgmode@gnu.org; Fri, 01 Nov 2019 20:47:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iQhZh-0004io-GG for emacs-orgmode@gnu.org; Fri, 01 Nov 2019 20:47:31 -0400 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]:46608) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iQhZf-0004fi-Hq for emacs-orgmode@gnu.org; Fri, 01 Nov 2019 20:47:27 -0400 Received: by mail-io1-xd32.google.com with SMTP id c6so12680661ioo.13 for ; Fri, 01 Nov 2019 17:47:24 -0700 (PDT) In-Reply-To: <87h83tokxy.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Gustavo Barros Cc: emacs-orgmode --00000000000004e3df0596526d61 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks Gustavo, notes below: On Sun, Oct 27, 2019 at 5:58 PM Gustavo Barros wrote: > Hi Nate, > > On Sun, Oct 27 2019, Nathan Neff wrote: > > > 1) My org-agenda-files show up in the list. For example, foo.org and > bar.org show up in the refile targets, despite the > > function should return nil if a heading does not contain "Tasks" > > Curiously, I=E2=80=99ve been scratching this itch just today. So I might = as well > share. > > I presume you are using some of the specific values of > `org-refile-use-outline-path'. If that=E2=80=99s the case, the file level= as a > refile target is hardcoded in `org-refile-get-targets', independently of > what you might have in `org-refile-target-verify-function'. > > We have somewhere in `org-refile-get-targets': > > #+begin_src emacs-lisp > (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)) > #+end_src > > (`tgs' is the local variable which is collecting candidates for return). > > So, you might not use `org-refile-use-outline-path'. In this case the > file info will be provided in the end of the refile target in > parentheses (for targets outside the current buffer). And the file level > will not be offered as a target. > > I, however like `org-refile-use-outline-path' and set it to 'file. But I > also want to not be able to refile to the file level. So I advised > `org-refile-get-targets' with: > > #+begin_src emacs-lisp > (defun my/org-refile-filter-targets (orig-fun &rest args) > (let ((targets (apply orig-fun args)) > (agenda-files (mapcar #'file-name-nondirectory org-agenda-files))= ) > (cl-remove-if (lambda (x) > (member (car x) agenda-files)) > targets))) > (advice-add 'org-refile-get-targets :around #'my/org-refile-filter-target= s) > #+end_src > > This presumes (setq org-refile-use-outline-path 'file). If you use any > other value, you should probably adjust the function=E2=80=99s let bound > variables for the case. This is also sort of hackish, so exert your own > due caution in choosing whether or not to use it. > Indeed, I do use org-refile-use-outline-path 'file. However, I have a simple directory specified for my org-agenda-files. ("~/org-mode") Therefore I'll need to do something a bit different. It appears that your solution creates "targets" which is the targets list of course, and then it creates "agenda-files" which goes through org-agenda-files and finds all the filenames in org-agenda files. It then mutates "targets", and removes any entry which is a filename from org-agenda-files. Since my org-agenda-files is simply ("~/org-mode/") none of the entries match. Hmmm, let me ask: Why not simply go through targets and remove any entry whose value is a simple filename? Why search org-agenda-files first? This function also assumes that the org-refile-targets always comes from org-agenda-files. I'll play with your function and see what I can get -- thank you for the head-start! Thanks --Nate > > HTH, > Gustavo. > --00000000000004e3df0596526d61 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Gustavo, notes below:

On Sun, Oct 2= 7, 2019 at 5:58 PM Gustavo Barros <gusbrs.2016@gmail.com> wrote:
Hi Nate,=

On Sun, Oct 27 2019, Nathan Neff wrote:

> 1) My org-agenda-files show up in the list.=C2=A0 For example, foo.org and bar.org s= how up in the refile targets, despite the
> function should return nil if a heading does not contain "Tasks&q= uot;

Curiously, I=E2=80=99ve been scratching this itch just today. So I might as= well
share.

I presume you are using some of the specific values of
`org-refile-use-outline-path'. If that=E2=80=99s the case, the file lev= el as a
refile target is hardcoded in `org-refile-get-targets', independently o= f
what you might have in `org-refile-target-verify-function'.

We have somewhere in `org-refile-get-targets':

#+begin_src emacs-lisp
(when (eq org-refile-use-outline-path 'file)
=C2=A0 (push (list (file-name-nondirectory f) f nil nil) tgs))
(when (eq org-refile-use-outline-path 'buffer-name)
=C2=A0 (push (list (buffer-name (buffer-base-buffer)) f nil nil) tgs))
(when (eq org-refile-use-outline-path 'full-file-path)
=C2=A0 (push (list (file-truename (buffer-file-name (buffer-base-buffer))) = f nil nil) tgs))
#+end_src

(`tgs' is the local variable which is collecting candidates for return)= .

So, you might not use `org-refile-use-outline-path'. In this case the file info will be provided in the end of the refile target in
parentheses (for targets outside the current buffer). And the file level will not be offered as a target.

I, however like `org-refile-use-outline-path' and set it to 'file. = But I
also want to not be able to refile to the file level. So I advised
`org-refile-get-targets' with:

#+begin_src emacs-lisp
(defun my/org-refile-filter-targets (orig-fun &rest args)
=C2=A0 (let ((targets (apply orig-fun args))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (agenda-files (mapcar #'file-name-nondirect= ory org-agenda-files)))
=C2=A0 =C2=A0 (cl-remove-if (lambda (x)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (memb= er (car x) agenda-files))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 targets))) (advice-add 'org-refile-get-targets :around #'my/org-refile-filter-= targets)
#+end_src

This presumes (setq org-refile-use-outline-path 'file). If you use any<= br> other value, you should probably adjust the function=E2=80=99s let bound variables for the case. This is also sort of hackish, so exert your own
due caution in choosing whether or not to use it.

=
Indeed, I do use org-refile-use-outline-path 'file.=C2=A0 Ho= wever, I have a simple
directory specified for my org-agenda-file= s. =C2=A0("~/org-mode") =C2=A0Therefore I'll need to=C2=A0
do something a bit different. =C2=A0

It ap= pears that your solution creates "targets" which is the targets l= ist of course, and
then it creates "agenda-files" which= goes through org-agenda-files and finds all the filenames
in org= -agenda files.

It then mutates "targets"= , and removes any entry which is a filename from org-agenda-files.

Since my org-agenda-files is simply ("~/org-mode/&quo= t;) none of the entries match.

Hmmm, let me ask: = =C2=A0Why not simply go through targets and remove any entry whose value is=
a simple filename?=C2=A0 Why search org-agenda-files first?=C2= =A0 This function also assumes that the org-refile-targets
always= comes from org-agenda-files.

I'll play with y= our function and see what I can get -- thank you for the head-start!
<= div>
Thanks
--Nate=C2=A0

HTH,
Gustavo.
--00000000000004e3df0596526d61--