emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* BUG: org-lint false missing arguments for macro with optional arguments
@ 2021-06-30 13:30 Michael Dauer
  2021-08-12  8:32 ` Ihor Radchenko
  2021-08-12 16:44 ` Maxim Nikulin
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Dauer @ 2021-06-30 13:30 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

Hi,

If I did not miss it there is no way to specify arguments as optional for a
macro definition.

I've the following:
(defun ct-action-plan (&optional up recently-done)
...
(push '("action_plan" . "(eval (ct-action-plan $1 $2))")
org-export-global-macros)

The arguments of the function are specified as optional. The macro just
call it with $1 and $2, which are nil if not stated like in the following:
{{{action_plan}}}

But here org-lint reports:
327 low   Missing arguments in macro "action_plan"

Is this a bug? Any ideas for a work-around to avoid confusion for my users.

BTW: I came to this after working around the other reported bug of lint to
ignore org-export-global-macros.

thx,
m

[-- Attachment #2: Type: text/html, Size: 960 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: BUG: org-lint false missing arguments for macro with optional arguments
  2021-06-30 13:30 BUG: org-lint false missing arguments for macro with optional arguments Michael Dauer
@ 2021-08-12  8:32 ` Ihor Radchenko
  2021-08-12 16:44 ` Maxim Nikulin
  1 sibling, 0 replies; 3+ messages in thread
From: Ihor Radchenko @ 2021-08-12  8:32 UTC (permalink / raw)
  To: Michael Dauer; +Cc: emacs-orgmode

Michael Dauer <mick.dauer@gmail.com> writes:

> If I did not miss it there is no way to specify arguments as optional for a
> macro definition.

You are right.

> Is this a bug? Any ideas for a work-around to avoid confusion for my users.

AFAIU it is not a bug, but rather a missing feature.

Best,
Ihor


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: BUG: org-lint false missing arguments for macro with optional arguments
  2021-06-30 13:30 BUG: org-lint false missing arguments for macro with optional arguments Michael Dauer
  2021-08-12  8:32 ` Ihor Radchenko
@ 2021-08-12 16:44 ` Maxim Nikulin
  1 sibling, 0 replies; 3+ messages in thread
From: Maxim Nikulin @ 2021-08-12 16:44 UTC (permalink / raw)
  To: emacs-orgmode

On 30/06/2021 20:30, Michael Dauer wrote:
> 
> I've the following:
> (defun ct-action-plan (&optional up recently-done)
> ...
> (push '("action_plan" . "(eval (ct-action-plan $1 $2))") 
> org-export-global-macros)

Didn't you report that adding macros directly to 
`org-export-global-macros' are not supported by `org-lint' at all?

On 30/06/2021 16:40, Michael Dauer wrote:
> I have a lot of global macros defined in org-export-global-macros.
> Wherever they are used in my org files org-lint reports them as undefined.
end of 30/06/2021 16:40 message

> The arguments of the function are specified as optional. The macro just 
> call it with $1 and $2, which are nil if not stated like in the following:
> {{{action_plan}}}
> 
> But here org-lint reports:
> 327 low   Missing arguments in macro "action_plan"

I can not reproduce it with current master and macros defined inside an 
org document

#+begin_src emacs-lisp :results silent :eval never-export
   (defun tst-macro-wrapper (args)
     (apply #'tst-macro args))
   (defun tst-macro (&optional one two)
     (format "one: %S two: %S." one two))
#+end_src

#+macro: mcropt (eval (tst-macro-wrapper _))
#+macro: mcrarg (eval (tst-macro $1 $2))

- opt ::
   + {{{mcropt}}}
   + {{{mcropt(onlyone)}}}
   + {{{mcropt(first,second)}}}

- arg ::
   + {{{mcrarg}}}
   + {{{mcrarg(onlyone)}}}
   + {{{mcrarg(first,second)}}}

`org-lint' reports no issues. mcropt relies on undocumented details of 
implementation.

> Is this a bug? Any ideas for a work-around to avoid confusion for my users.

Since eval expression may be arbitrary complex, it is a challenge to 
parse a general form to find whether arguments are optional at 
particular call site. More precise analysis of macro arguments would be 
a great feature. Unsure if it is feasible.

P.S. Various static code analyzers for programming languages allows to 
suppress particular warnings at specific lines by adding special comments.

P.P.S "Rest" arguments substitution in macros (e.g. $_) may mitigate an 
issue with phrases including commas as an argument 
https://orgmode.org/list/s7gfc6$hj1$1@ciao.gmane.io



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-12 16:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-30 13:30 BUG: org-lint false missing arguments for macro with optional arguments Michael Dauer
2021-08-12  8:32 ` Ihor Radchenko
2021-08-12 16:44 ` Maxim Nikulin

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