From: Kaushal Modi <kaushal.modi@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>, emacs-orgmode@gnu.org
Subject: Add an optional HOLD argument to "n" Org macro (Was: [RFC] The "c" Org macro)
Date: Wed, 14 Jun 2017 18:33:50 +0000 [thread overview]
Message-ID: <CAFyQvY19R4gEkEP1pBwvVguyC081u2qn5WuDHkC_mGv_S_5YrQ@mail.gmail.com> (raw)
In-Reply-To: <CAFyQvY0+rLM+kKTqHGNuMnL9asmafnLYqLJ97UOGqLaXuFmbDw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3256 bytes --]
I was writing something along the lines of this when I needed to specify
the n macro to hold its previous value and not increment at all.
=====
* Week {{{n(wk)}}}: Python Basics
# 1
** {{{n}}}. Introduction to Python
# 1
** {{{n}}}. Core Elements of Programs
# 2
*** {{{n(,,hold)}}}.{{{n(topic,reset)}}}: Bindings
# 2.1
*** {{{n(,,hold)}}}.{{{n(topic)}}}: Strings
# 2.2
*** {{{n(,,hold)}}}.{{{n(topic)}}}: Input/Output
# 2.3
* Week {{{n(wk)}}}: Simple Programs
# 2
** {{{n}}}. Simple Algorithms
# 3
** {{{n}}}. Functions
# 4
* Week {{{n(wk)}}}: Structured Types
# 3
** {{{n}}}. Tuples and Lists
# 5
** {{{n}}}. Dictionaries
# 6
=====
Below is an informal diff to show how the hold feature was implemented.
diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index 338c98811d..cc74cebd0a 100644
--- a/lisp/org-macro.el
+++ b/lisp/org-macro.el
@@ -40,7 +40,7 @@
;; {{{property(node-property)}}},
;; {{{input-file}}},
;; {{{modification-time(format-string)}}},
-;; {{{n(counter,reset}}}.
+;; {{{n(counter,reset,hold}}}.
;; Upon exporting, "ox.el" will also provide {{{author}}}, {{{date}}},
;; {{{email}}} and {{{title}}} macros.
@@ -163,7 +163,7 @@ function installs the following ones: \"property\",
;; Initialize and install "n" macro.
(org-macro--counter-initialize)
(funcall update-templates
- (cons "n" "(eval (org-macro--counter-increment \"$1\" \"$2\"))"))
+ (cons "n" "(eval (org-macro--counter-increment \"$1\" \"$2\"
\"$3\"))"))
(setq org-macro-templates templates)))
(defun org-macro-expand (macro templates)
@@ -327,14 +327,20 @@ Return a list of arguments, as strings. This is the
opposite of
"Initialize `org-macro--counter-table'."
(setq org-macro--counter-table (make-hash-table :test #'equal)))
-(defun org-macro--counter-increment (name &optional reset)
+(defun org-macro--counter-increment (name &optional reset hold)
"Increment counter NAME.
-NAME is a string identifying the counter. When non-nil, optional
-argument RESET is a string. If it represents an integer, set the
-counter to this number. Any other non-empty string resets the
-counter to 1."
+NAME is a string identifying the counter.
+
+When non-nil, optional argument RESET is a string. If it represents
+an integer, set the counter to this number. Any other non-empty
+string resets the counter to 1.
+
+When non-nil, optional argument HOLD is a string. If it is a
+non-empty string, keep the NAME counter at its previous value."
(puthash name
- (cond ((not (org-string-nw-p reset))
+ (cond ((org-string-nw-p hold)
+ (gethash name org-macro--counter-table 0))
+ ((not (org-string-nw-p reset))
(1+ (gethash name org-macro--counter-table 0)))
((string-match-p "\\`[ \t]*[0-9]+[ \t]*\\'" reset)
(string-to-number reset))
I haven't yet created a proper formatted patch, because I don't know if
this is the best implementation. Would it be better to rename the RESET
option to something more generic, like ARG? That way,
- If ARG is a "-" string, the counter value will be held and not
incremented.
- If ARG is a number represented as a string, it set the NAME counter to
that value (like now).
- Else if ARG is a non-empty string, it resets the NAME counter to 1 (like
now).
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 5822 bytes --]
next prev parent reply other threads:[~2017-06-14 18:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <2ee94a64a94b46259b0da6e7d34675c9@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-05-08 14:00 ` [RFC] The "c" Org macro Eric S Fraga
2017-05-08 15:32 ` Dushyant Juneja
[not found] ` <a4c6d561b12a4cc8ad4fe8c017fa2121@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-05-08 15:59 ` Eric S Fraga
2017-05-08 16:52 ` Nicolas Goaziou
2017-05-09 7:35 ` Carsten Dominik
2017-05-09 10:35 ` Nicolas Goaziou
2017-05-09 11:25 ` Rasmus
2017-05-09 16:10 ` Nicolas Goaziou
[not found] ` <2069df8c23bc43f3b04b6e203b96be9d@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-05-11 8:45 ` Eric S Fraga
2017-05-21 13:37 ` Nicolas Goaziou
2017-05-22 3:24 ` Kaushal Modi
2017-05-22 5:58 ` Nicolas Goaziou
2017-05-22 10:46 ` Kaushal Modi
2017-05-22 11:47 ` Nicolas Goaziou
2017-05-22 13:00 ` Kaushal Modi
2017-05-22 13:10 ` Kaushal Modi
2017-05-22 13:13 ` Nicolas Goaziou
2017-05-22 13:39 ` Kaushal Modi
2017-05-25 10:42 ` Nicolas Goaziou
2017-05-25 18:31 ` Kaushal Modi
2017-06-14 17:52 ` Kaushal Modi
2017-06-14 18:33 ` Kaushal Modi [this message]
2017-06-14 19:47 ` Add an optional HOLD argument to "n" " Nicolas Goaziou
2017-06-15 13:10 ` Kaushal Modi
2017-06-15 15:25 ` Kaushal Modi
2017-06-15 16:07 ` Nicolas Goaziou
2017-06-15 18:07 ` Kaushal Modi
2017-06-17 14:34 ` Kaushal Modi
2017-06-17 23:24 ` Nicolas Goaziou
2017-06-18 4:03 ` Kaushal Modi
2017-06-18 7:16 ` Nicolas Goaziou
2017-06-18 7:45 ` Kaushal Modi
2017-06-14 19:44 ` [RFC] The "c" " Nicolas Goaziou
[not found] ` <a8f5841641834b4cb51af85a3df785da@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-05-22 8:34 ` Eric S Fraga
2017-05-08 16:30 ` Robert Horn
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=CAFyQvY19R4gEkEP1pBwvVguyC081u2qn5WuDHkC_mGv_S_5YrQ@mail.gmail.com \
--to=kaushal.modi@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=mail@nicolasgoaziou.fr \
/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).