emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Nafiz Islam <nafiz.islam1000@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] function and symbol for headline and olp for org-capture-templates
Date: Mon, 20 May 2024 10:53:40 +0000	[thread overview]
Message-ID: <87pltgrbyj.fsf@localhost> (raw)
In-Reply-To: <CADEw4oVkcOGLnka3YXCszfEEv+8z2gTj_=YH-RkfBuhkwaz6wA@mail.gmail.com>

Nafiz Islam <nafiz.islam1000@gmail.com> writes:

>> I've also updated the docstring for `org-capture-templates', filtered out
>> incorrect target, and updated `org-capture-expand-olp' to take file
>> argument.

I do not think that it does what you expect.
AFAIU, the idea was to pass the FILE and extra OLP arguments to the
custom function provided by the user. But it is not what your code does.

> +(defun org-capture-expand-function-or-symbol (input)
> +  "Expand functions and symbols. When INPUT is a
> +function, call it. When it is a variable, return
> +its value. In any other case, return `nil'."
> +  (let* ((output (cond ((functionp input) (funcall input))
> +		       ((and (symbolp input) (boundp input)) (symbol-value input))
> +                       (t nil))))
> +    output))
> ...
> +(defun org-capture-expand-olp (file &rest olp)
> +  "Expand functions, symbols and outline paths for OLP.
> +When OLP is a function, call it. When it is a variable,
> +return its value. When it is a list of string, return it.
> +In any other case, return `nil'. The current buffer is
> +set to the FILE before executing OLP as a function."
> +  (with-current-buffer (find-file-noselect file)
> +    (let* ((final-olp (cond ((stringp (car olp)) olp)
> +                            ((not (cdr olp)) (org-capture-expand-function-or-symbol (car olp)))
> +                            (t (error "Invalid outline path: %S" olp)))))
> +      final-olp)))

You are still calling `org-capture-expand-function-or-symbol' without
passing the rest of OLP there. Or was it the intention?

Also, is there any point calling `find-file-noselect' when the outline
path spec is _not_ a function?

Finally, you need to describe the calling convention and environment
when the function spec for OLP is called - that it is called with no (or
some?) arguments and that the current buffer is the FILE-visiting buffer.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  reply	other threads:[~2024-05-20 10:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-19 23:34 [PATCH] function and symbol for headline and olp for org-capture-templates Nafiz Islam
2024-05-19 23:43 ` Nafiz Islam
2024-05-20 10:53   ` Ihor Radchenko [this message]
2024-05-21 21:00     ` Nafiz Islam
2024-05-22 11:11       ` Nafiz Islam
2024-05-22 11:15         ` Ihor Radchenko
  -- strict thread matches above, loose matches on Subject: below --
2024-06-01 16:38 Nafiz Islam
2024-06-05  9:09 ` Ihor Radchenko
2024-06-05 21:16   ` Bastien Guerry
     [not found]   ` <f2b85669-a0fc-40c6-891a-1319d0582fe0@gmail.com>
     [not found]     ` <87frtpgj2w.fsf@localhost>
2024-06-09 14:59       ` Nafiz Islam
2024-06-09 17:03         ` Ihor Radchenko
     [not found]   ` <3508dbb0-a8ee-4217-af21-a9fc3ac46eb9@gmail.com>
     [not found]     ` <874ja4ak0q.fsf@localhost>
2024-06-15 21:45       ` Nafiz Islam
2024-06-16 12:20         ` Ihor Radchenko
     [not found]           ` <c98ba108-c07e-4c17-a806-524444367d9d@gmail.com>
     [not found]             ` <87plsfa2nt.fsf@localhost>
2024-06-18 12:05               ` Nafiz Islam
2024-06-18 12:36                 ` Ihor Radchenko
2024-05-13 22:53 Nafiz Islam
2024-05-13 23:08 ` Nafiz Islam
2024-05-17 12:48   ` Ihor Radchenko

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=87pltgrbyj.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=nafiz.islam1000@gmail.com \
    /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 public 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).