emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Thuna <thuna.cing@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Multiline Macros
Date: Tue, 27 Aug 2024 02:06:45 +0200	[thread overview]
Message-ID: <87frqqj0bu.fsf@gmail.com> (raw)

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

Here's a package which allows defining multiline Org macros via
#+BEGIN_MACRO ... #+END_MACRO: https://git.sr.ht/~thuna/org-multiline-macro
(I've also attached the elisp file here.)

The README should explain it (hopefully) well enough, but I'll also try
explain it here:

- To define a multiline macro, do
  
  #+BEGIN_MACRO foo
  Some text which will be inserted,
  plus some more in a line.
  #+END_MACRO
  
  and {{{foo}}} will be replaced by that body, newlines included.

- Arguments can be used in the text much the same way:
  
  #+BEGIN_MACRO license
  Copyright (C) $1 {{{author}}} <{{{email}}}>
  #+END_MACRO

- You can create an eval macro by starting the macro contents with
  `(eval':
  
  #+BEGIN_MACRO add-one
  (eval (number-to-string
         (1+ (string-to-number $1))))
  #+END_MACRO
  
  and arguments work here as usual as well.

- You can bypass the need for the leading `(eval' by giving the block an
  `:eval yes' parameter,

  #+BEGIN_MACRO add-one :eval yes
  (number-to-string
   (1+ (string-to-number $1)))
  #+END_MACRO

  This also allows more than one form.  All the forms are evaluated in
  order, and the last one's result is the result of the macro.

  #+BEGIN_MACRO add-one-loudly :eval yes
  (setq $1 (string-to-number $1))
  (message "adding one to: %d" $1)
  (number-to-string (1+ $1))
  #+END_MACRO

This is basically all this package does.  There are a couple known
problems, which are listed in the README but which I will also repeat
here for completeness:

- #+BEGIN_MACRO is not a distinct element type but a special block which
   I am hacking org-macro.el to handle.  This comes with its fair share
   of problems, export being the most relevant one that I know of right
   now.

  The fix is to just make it a distinct element, but I want to tackle
  that only after I have figured out all the other kinks.

- Macro blocks are not editable.  This is doable however there is an
  additional challenge in that they should be editable as emacs lisp
  source blocks when they are eval macro blocks (maybe not if they are
  the implicit kind [aka without the :eval yes]), and I have no idea
  where to even start with this.  Some help from people familiar with
  the relevant code would be appreciated.

- :eval no should technically be forcing a macro block as non-eval, even
  if it starts with `(eval'.  This is currently not the case, because I
  didn't want to duplicate the code which makes it so.

- Some testing for SETUPFILE following would be appreciated.  I did a
  *very* light test, but I don't know if it actually works or not.  I
  just copied the code from a different function which handles it.

All thoughts, ideas, suggestions, and bug reports are welcome.


[-- Attachment #2: org-multiline-macro.el --]
[-- Type: application/x-emacs-lisp, Size: 6003 bytes --]

             reply	other threads:[~2024-08-27  0:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27  0:06 Thuna [this message]
2024-11-03 17:52 ` Multiline Macros 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=87frqqj0bu.fsf@gmail.com \
    --to=thuna.cing@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).