2015-10-26 00:56:00 +00:00
|
|
|
|
;;; org-macro.el --- Macro Replacement Code for Org -*- lexical-binding: t; -*-
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
2024-01-02 01:47:10 +00:00
|
|
|
|
;; Copyright (C) 2013-2024 Free Software Foundation, Inc.
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
|
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
|
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 19:57:31 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2013-02-23 08:56:24 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2013-02-16 13:03:59 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
2013-02-23 08:56:24 +00:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2013-02-16 13:03:59 +00:00
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Macros are expanded with `org-macro-replace-all', which relies
|
|
|
|
|
;; internally on `org-macro-expand'.
|
|
|
|
|
|
|
|
|
|
;; Default templates for expansion are stored in the buffer-local
|
|
|
|
|
;; variable `org-macro-templates'. This variable is updated by
|
|
|
|
|
;; `org-macro-initialize-templates', which recursively calls
|
|
|
|
|
;; `org-macro--collect-macros' in order to read setup files.
|
|
|
|
|
|
2021-09-16 10:32:43 +00:00
|
|
|
|
;; Argument in macros are separated with commas. Proper escaping rules
|
2015-01-20 23:25:47 +00:00
|
|
|
|
;; are implemented in `org-macro-escape-arguments' and arguments can
|
|
|
|
|
;; be extracted from a string with `org-macro-extract-arguments'.
|
|
|
|
|
|
2013-02-16 13:03:59 +00:00
|
|
|
|
;; Along with macros defined through #+MACRO: keyword, default
|
|
|
|
|
;; templates include the following hard-coded macros:
|
2017-05-08 10:38:38 +00:00
|
|
|
|
;; {{{time(format-string)}}},
|
|
|
|
|
;; {{{property(node-property)}}},
|
|
|
|
|
;; {{{input-file}}},
|
|
|
|
|
;; {{{modification-time(format-string)}}},
|
2017-06-18 02:12:20 +00:00
|
|
|
|
;; {{{n(counter,action}}}.
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
|
|
|
|
;; Upon exporting, "ox.el" will also provide {{{author}}}, {{{date}}},
|
|
|
|
|
;; {{{email}}} and {{{title}}} macros.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
2022-08-04 13:53:05 +00:00
|
|
|
|
|
|
|
|
|
(require 'org-macs)
|
|
|
|
|
(org-assert-version)
|
|
|
|
|
|
2016-05-26 14:16:31 +00:00
|
|
|
|
(require 'cl-lib)
|
2013-06-01 09:21:48 +00:00
|
|
|
|
(require 'org-macs)
|
2015-05-30 12:28:35 +00:00
|
|
|
|
(require 'org-compat)
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
2020-04-26 20:57:47 +00:00
|
|
|
|
(declare-function org-collect-keywords "org" (keywords &optional unique directory))
|
2022-01-06 17:39:05 +00:00
|
|
|
|
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
|
2013-02-16 13:03:59 +00:00
|
|
|
|
(declare-function org-element-context "org-element" (&optional element))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(declare-function org-element-copy "org-element-ast" (datum))
|
2017-06-05 15:05:58 +00:00
|
|
|
|
(declare-function org-element-macro-parser "org-element" ())
|
2021-10-16 16:01:56 +00:00
|
|
|
|
(declare-function org-element-keyword-parser "org-element" (limit affiliated))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(declare-function org-element-put-property "org-element-ast" (node property value))
|
2017-11-22 22:35:50 +00:00
|
|
|
|
(declare-function org-element-parse-secondary-string "org-element" (string restriction &optional parent))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(declare-function org-element-property "org-element-ast" (property node))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(declare-function org-element-begin "org-element" (node))
|
|
|
|
|
(declare-function org-element-end "org-element" (node))
|
2017-11-22 22:35:50 +00:00
|
|
|
|
(declare-function org-element-restriction "org-element" (element))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
|
|
|
|
|
(declare-function org-element-type-p "org-element-ast" (node types))
|
2018-10-01 19:33:49 +00:00
|
|
|
|
(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
|
2017-06-13 15:41:14 +00:00
|
|
|
|
(declare-function org-file-contents "org" (file &optional noerror nocache))
|
2022-06-16 04:15:03 +00:00
|
|
|
|
(declare-function org-in-commented-heading-p "org" (&optional no-inheritance element))
|
2019-03-12 09:41:36 +00:00
|
|
|
|
(declare-function org-link-search "ol" (s &optional avoid-pos stealth))
|
2015-05-30 12:28:35 +00:00
|
|
|
|
(declare-function org-mode "org" ())
|
2016-05-18 09:23:46 +00:00
|
|
|
|
(declare-function vc-backend "vc-hooks" (f))
|
2016-05-19 02:01:59 +00:00
|
|
|
|
(declare-function vc-call "vc-hooks" (fun file &rest args) t)
|
2022-09-24 13:17:23 +00:00
|
|
|
|
(declare-function vc-exec-after "vc-dispatcher" (code &optional success))
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
2018-10-01 19:33:49 +00:00
|
|
|
|
(defvar org-link-search-must-match-exact-headline)
|
|
|
|
|
|
2013-02-16 13:03:59 +00:00
|
|
|
|
;;; Variables
|
|
|
|
|
|
2015-11-05 16:47:38 +00:00
|
|
|
|
(defvar-local org-macro-templates nil
|
2013-02-16 13:03:59 +00:00
|
|
|
|
"Alist containing all macro templates in current buffer.
|
|
|
|
|
Associations are in the shape of (NAME . TEMPLATE) where NAME
|
|
|
|
|
stands for macro's name and template for its replacement value,
|
|
|
|
|
both as strings. This is an internal variable. Do not set it
|
|
|
|
|
directly, use instead:
|
|
|
|
|
|
|
|
|
|
#+MACRO: name template")
|
|
|
|
|
|
|
|
|
|
;;; Functions
|
|
|
|
|
|
2021-04-11 17:17:54 +00:00
|
|
|
|
(defun org-macro--makeargs (template)
|
|
|
|
|
"Compute the formal arglist to use for TEMPLATE."
|
|
|
|
|
(let ((max 0) (i 0))
|
|
|
|
|
(while (string-match "\\$\\([0-9]+\\)" template i)
|
|
|
|
|
(setq i (match-end 0))
|
|
|
|
|
(setq max (max max (string-to-number (match-string 1 template)))))
|
|
|
|
|
(let ((args '(&rest _)))
|
2021-04-16 22:06:58 +00:00
|
|
|
|
(if (< max 1) args ;Avoid `&optional &rest', refused by Emacs-26!
|
|
|
|
|
(while (> max 0)
|
|
|
|
|
(push (intern (format "$%d" max)) args)
|
|
|
|
|
(setq max (1- max)))
|
|
|
|
|
(cons '&optional args)))))
|
2021-04-11 17:17:54 +00:00
|
|
|
|
|
|
|
|
|
(defun org-macro--set-templates (templates)
|
2019-04-29 18:35:23 +00:00
|
|
|
|
"Set template for the macro NAME.
|
|
|
|
|
VALUE is the template of the macro. The new value override the
|
2021-04-11 17:17:54 +00:00
|
|
|
|
previous one, unless VALUE is nil. Return the updated list."
|
|
|
|
|
(let ((new-templates nil))
|
|
|
|
|
(pcase-dolist (`(,name . ,value) templates)
|
|
|
|
|
(let ((old-definition (assoc name new-templates)))
|
|
|
|
|
(when (and (stringp value) (string-match-p "\\`(eval\\>" value))
|
|
|
|
|
;; Pre-process the evaluation form for faster macro expansion.
|
|
|
|
|
(let* ((args (org-macro--makeargs value))
|
|
|
|
|
(body
|
|
|
|
|
(condition-case nil
|
|
|
|
|
;; `value' is of the form "(eval ...)" but we
|
|
|
|
|
;; don't want this to mean to pass the result to
|
|
|
|
|
;; `eval' (which would cause double evaluation),
|
|
|
|
|
;; so we strip the `eval' away with `cadr'.
|
|
|
|
|
(cadr (read value))
|
|
|
|
|
(error
|
|
|
|
|
(user-error "Invalid definition for macro %S" name)))))
|
|
|
|
|
(setq value (eval (macroexpand-all `(lambda ,args ,body)) t))))
|
|
|
|
|
(cond ((and value old-definition) (setcdr old-definition value))
|
|
|
|
|
(old-definition)
|
|
|
|
|
(t (push (cons name (or value "")) new-templates)))))
|
|
|
|
|
new-templates))
|
2019-04-29 18:35:23 +00:00
|
|
|
|
|
2020-04-26 20:57:47 +00:00
|
|
|
|
(defun org-macro--collect-macros ()
|
2013-02-16 13:03:59 +00:00
|
|
|
|
"Collect macro definitions in current buffer and setup files.
|
2020-04-26 20:57:47 +00:00
|
|
|
|
Return an alist containing all macro templates found."
|
2021-04-11 17:17:54 +00:00
|
|
|
|
(let ((templates
|
2021-10-23 12:32:00 +00:00
|
|
|
|
`(("author" . ,(org-macro--find-keyword-value "AUTHOR" t))
|
2021-04-11 17:17:54 +00:00
|
|
|
|
("email" . ,(org-macro--find-keyword-value "EMAIL"))
|
|
|
|
|
("title" . ,(org-macro--find-keyword-value "TITLE" t))
|
|
|
|
|
("date" . ,(org-macro--find-date)))))
|
2020-04-26 20:57:47 +00:00
|
|
|
|
(pcase (org-collect-keywords '("MACRO"))
|
|
|
|
|
(`(("MACRO" . ,values))
|
|
|
|
|
(dolist (value values)
|
|
|
|
|
(when (string-match "^\\(\\S-+\\)[ \t]*" value)
|
|
|
|
|
(let ((name (match-string 1 value))
|
|
|
|
|
(definition (substring value (match-end 0))))
|
2021-04-11 17:17:54 +00:00
|
|
|
|
(push (cons name definition) templates))))))
|
2019-04-29 18:35:23 +00:00
|
|
|
|
templates))
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
2021-04-11 17:17:54 +00:00
|
|
|
|
(defun org-macro-initialize-templates (&optional default)
|
2013-02-16 13:03:59 +00:00
|
|
|
|
"Collect macro templates defined in current buffer.
|
2018-07-07 10:10:48 +00:00
|
|
|
|
|
2021-04-11 17:17:54 +00:00
|
|
|
|
DEFAULT is a list of globally available templates.
|
|
|
|
|
|
|
|
|
|
Templates are stored in buffer-local variable `org-macro-templates'.
|
2018-07-07 10:10:48 +00:00
|
|
|
|
|
|
|
|
|
In addition to buffer-defined macros, the function installs the
|
|
|
|
|
following ones: \"n\", \"author\", \"email\", \"keyword\",
|
2018-07-07 10:45:40 +00:00
|
|
|
|
\"time\", \"property\", and, if the buffer is associated to
|
|
|
|
|
a file, \"input-file\" and \"modification-time\"."
|
2019-03-12 09:41:36 +00:00
|
|
|
|
(require 'org-element)
|
2018-03-23 22:40:56 +00:00
|
|
|
|
(org-macro--counter-initialize) ;for "n" macro
|
|
|
|
|
(setq org-macro-templates
|
|
|
|
|
(nconc
|
2021-04-11 17:17:54 +00:00
|
|
|
|
;; Install user-defined macros. Local macros have higher
|
|
|
|
|
;; precedence than global ones.
|
|
|
|
|
(org-macro--set-templates (append default (org-macro--collect-macros)))
|
2018-03-23 22:40:56 +00:00
|
|
|
|
;; Install file-specific macros.
|
|
|
|
|
(let ((visited-file (buffer-file-name (buffer-base-buffer))))
|
|
|
|
|
(and visited-file
|
|
|
|
|
(file-exists-p visited-file)
|
|
|
|
|
(list
|
|
|
|
|
`("input-file" . ,(file-name-nondirectory visited-file))
|
|
|
|
|
`("modification-time" .
|
2021-04-11 17:17:54 +00:00
|
|
|
|
,(let ((modtime (file-attribute-modification-time
|
|
|
|
|
(file-attributes visited-file))))
|
2021-04-18 23:11:37 +00:00
|
|
|
|
(lambda (arg1 &optional arg2 &rest _)
|
2021-04-11 17:17:54 +00:00
|
|
|
|
(format-time-string
|
|
|
|
|
arg1
|
|
|
|
|
(or (and (org-string-nw-p arg2)
|
|
|
|
|
(org-macro--vc-modified-time visited-file))
|
|
|
|
|
modtime))))))))
|
2019-04-29 18:35:23 +00:00
|
|
|
|
;; Install generic macros.
|
2021-04-11 17:17:54 +00:00
|
|
|
|
'(("keyword" . (lambda (arg1 &rest _)
|
2021-10-25 14:47:48 +00:00
|
|
|
|
(org-macro--find-keyword-value arg1 t)))
|
2021-04-11 17:17:54 +00:00
|
|
|
|
("n" . (lambda (&optional arg1 arg2 &rest _)
|
|
|
|
|
(org-macro--counter-increment arg1 arg2)))
|
|
|
|
|
("property" . (lambda (arg1 &optional arg2 &rest _)
|
|
|
|
|
(org-macro--get-property arg1 arg2)))
|
|
|
|
|
("time" . (lambda (arg1 &rest _)
|
|
|
|
|
(format-time-string arg1)))))))
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
|
|
|
|
(defun org-macro-expand (macro templates)
|
|
|
|
|
"Return expanded MACRO, as a string.
|
|
|
|
|
MACRO is an object, obtained, for example, with
|
|
|
|
|
`org-element-context'. TEMPLATES is an alist of templates used
|
|
|
|
|
for expansion. See `org-macro-templates' for a buffer-local
|
|
|
|
|
default value. Return nil if no template was found."
|
|
|
|
|
(let ((template
|
|
|
|
|
;; Macro names are case-insensitive.
|
|
|
|
|
(cdr (assoc-string (org-element-property :key macro) templates t))))
|
|
|
|
|
(when template
|
2021-04-11 17:17:54 +00:00
|
|
|
|
(let* ((value
|
|
|
|
|
(if (functionp template)
|
|
|
|
|
(apply template (org-element-property :args macro))
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"\\$[0-9]+"
|
|
|
|
|
(lambda (m)
|
|
|
|
|
(or (nth (1- (string-to-number (substring m 1)))
|
|
|
|
|
(org-element-property :args macro))
|
|
|
|
|
;; No argument: remove place-holder.
|
|
|
|
|
""))
|
|
|
|
|
template nil 'literal))))
|
2017-12-16 15:07:09 +00:00
|
|
|
|
;; Force return value to be a string.
|
2013-02-16 13:03:59 +00:00
|
|
|
|
(format "%s" (or value ""))))))
|
|
|
|
|
|
2017-11-21 21:25:17 +00:00
|
|
|
|
(defun org-macro-replace-all (templates &optional keywords)
|
2013-02-16 13:03:59 +00:00
|
|
|
|
"Replace all macros in current buffer by their expansion.
|
2014-09-28 03:50:23 +00:00
|
|
|
|
|
2013-02-16 13:03:59 +00:00
|
|
|
|
TEMPLATES is an alist of templates used for expansion. See
|
2014-09-28 03:50:23 +00:00
|
|
|
|
`org-macro-templates' for a buffer-local default value.
|
|
|
|
|
|
2015-05-10 08:05:46 +00:00
|
|
|
|
Optional argument KEYWORDS, when non-nil is a list of keywords,
|
2017-11-21 21:25:17 +00:00
|
|
|
|
as strings, where macro expansion is allowed.
|
|
|
|
|
|
|
|
|
|
Return an error if a macro in the buffer cannot be associated to
|
|
|
|
|
a definition in TEMPLATES."
|
2017-08-21 19:21:30 +00:00
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(let ((properties-regexp (format "\\`EXPORT_%s\\+?\\'"
|
|
|
|
|
(regexp-opt keywords)))
|
|
|
|
|
record)
|
|
|
|
|
(while (re-search-forward "{{{[-A-Za-z0-9_]" nil t)
|
|
|
|
|
(unless (save-match-data (org-in-commented-heading-p))
|
|
|
|
|
(let* ((datum (save-match-data (org-element-context)))
|
|
|
|
|
(type (org-element-type datum))
|
|
|
|
|
(macro
|
|
|
|
|
(cond
|
|
|
|
|
((eq type 'macro) datum)
|
|
|
|
|
;; In parsed keywords and associated node
|
|
|
|
|
;; properties, force macro recognition.
|
|
|
|
|
((or (and (eq type 'keyword)
|
|
|
|
|
(member (org-element-property :key datum) keywords))
|
|
|
|
|
(and (eq type 'node-property)
|
|
|
|
|
(string-match-p properties-regexp
|
|
|
|
|
(org-element-property :key datum))))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
|
(org-element-macro-parser))))))
|
|
|
|
|
(when macro
|
Re-implement org-element-cache and add headline support
* lisp/org-element.el (org-element-with-disabled-cache): New macro.
(org-element-greater-elements): Add new org-data element. It
functions like a virtual headline containing the whole buffer. The
org-data properties are like headlie properties, but according to the
top-level drawer. org-data's category is the buffer's category as
defined by top-level property drawer, #+CATEGORY keyworsd, and the
buffer file name.
(org-element--cache-element-properties, org-element-set-element): New
variable containing properties to be transferred when updating changed
element in cache in `org-element-set-element'.
(org-element--get-node-properties): Allow parsing node propreties in
top-level drawer when new optional argument is passed. Respect
PROPERTY+ syntax.
(org-element--get-global-node-properties): New function. It returns
node properties for top-level property drawer.
(org-element-org-data-parser, org-element-org-data-interpreter):
Implement the new org-data element.
(org-element-headline-parser, org-element-section-parser): Add new
:robust-begin and :robust-end
properties delimiting safe changes that do not modify headline
element.
(org-element--list-struct): Fix cache update when adding a headline
inside list.
(org-element--current-element): Implement cache support. Record
parsing mode (:mode) and parsing granularity (:granularity) in the
element properties.
(org-element-parse-buffer, org-element--next-mode): Support new
org-data element.
(org-element--parse-elements): Record parsing granularity in the
returned tree
(org-element-use-cache): Enable cache by default.
(org-element-cache-persistent): New variable controlling cache
persistance across sessions. Enabled by default.
(org-element--cache-self-verify,
org-element--cache-self-verify-frequency,
org-element--cache-diagnostics, org-element--cache-map-statistics,
org-element--cache-map-statistics-threshold,
org-element--cache-diagnostics-level,
org-element--cache-diagnostics-ring,
org-element--cache-diagnostics-ring-size): New variables controlling
cache diagnostics and self-diagnostics. Greatly simplifies cache
debugging.
(org-element--cache, org-element--cache-sync-requests,
org-element--cache-sync-timer): Make cache buffer-local by default.
(org-element--headline-cache): Implement separate cache storing only
headlines and inlinetasks.
(org-element--cache-size, org-element--headline-cache-size): New
variables containing cache sizes. This is much faster than
`avl-tree-size'.
(org-element--cache-sync-requests): Update docstring explaning the
request list structure.
(org-element--cache-sync-keys-value): New variable replacing
`org-element--cache-sync-keys' hash table. The hash table was not
reliable because it was using elements as keys. Upon any cached
element update/shift, the keys were invalidated making cache ordering
incorrect and breaking the cache badly. Now, the cache keys are
stored as :org-element--cache-sync-key element property and the new
variable stores marker value indicating the current sync request
cycle. See `org-element--cache-key' for more details.
(org-element--cache-change-tic): New variable controlling buffer
modification count that is registered in cache. This variable allows
catching "stealth" edits.
(org-element--cache-non-modifying-commands): New variable listing
commands that will not be slown down if we fill cache on the fly.
(org-element--request-key, org-element--request-beg,
org-element--request-end, org-element--request-offset,
org-element--request-parent, org-element--request-phase): New macros.
They improve code readability (especially when using nameless-mode).
(org-element--format-element, org-element--cache-log-message,
org-element--cache-warn): New macros implementing generic logging
functionality.
(org-element--cache-key): Add section and org-data element support.
Change cache key storage from hash map to :org-element--cache-sync-key
element property + `org-element--cache-sync-keys-value'. We use the
latter to group all the cache keys during a single cache request
sequence. Once sync request is fully complete, the
`org-element--cache-sync-keys-value' is updated making all the old
sync keys obsolete (they will still be store as element properties).
(org-element--headline-cache-root): New function returning headline
cache root.
(org-element--cache-active-p): Prevent cache updates when
`inhibit-modification-hooks' is non-nil, unless non-nil optional
argument is provided.
(org-element--cache-find): Share cache between indirect buffers and
the base buffer. We have to do it because after-change hooks for
indirect buffer are not called in the base buffer and vice versa. Add
support for section and org-data elements.
(org-element--cache-put): Implement new approach for cache key
storage. Add diagnostics. Indicate cached elements using :cached
element property. Support cache size calculation.
(org-element--cache-remove): Invalidate parent contents when removing
element. Support cache size calculation. Detect cache corruption due
to misordered elements.
(org-element--cache-shift-positions): Support :robust-begin and
:robust-end element properties.
(org-element--cache-sync): Add diagnostics. Add detailed comments.
Prevent slowdown when large cache chunks need to be deleted forcing
O(N) complexity cutoff. In phase 2, fix cases when next request
contains deleted cache key. In phase 2, fix scenario when newly
inserted element intersects with existing elements in cache. In phase
2, detect obsolete parents removed from cache.
(org-element--open-end-p): New function checking if an element can
have blank lines right after its :contents-end.
(org-element--parse-to): Do not alter match data. Process complex
parsing mode changes correctly. Support headlines in cache. Support
org-data parsing. Add detailed comments. Add diagnostics.
(org-element--cache-sensitive-re): Make list lines sensitive.
(org-element--cache-change-warning): Update docstring. Now, the
variable can have t, nil, and number values. Numbers are used to
provide more details about changed headlines.
(org-element--cache-before-change, org-element--cache-after-change):
Handle headline hierarchy. Properly handle cache in indirect
buffers.
(org-element--cache-after-change): Update docstring clarifying the
return values. Add special handling for headline and org-data
elements updating them in-place instead of removing together with the
whole contents when possible. Use :robust-begin/:robust-end element
properties to detect robust changes.
(org-element--cache-submit-request): Add detailed comments. Correctly
handle cache in indirect buffers. Delegate element modifications to
`org-element--cache-for-removal'.
(org-element--cache-verify-element): New function for cache
self-verification.
(org-element--cache-persist-before-write,
org-element--cache-persist-before-read,
org-element--cache-persist-after-read): Implement cache persistance.
(org-element-cache-reset): Correctly handle cache in indirect
buffers. Support cache persistance. Support new cache size
calculation and new cache key schema.
(org-element-cache-map): New function analagous to `org-element-map',
but much faster. The function overperforms org-ql written by Adam
Porter aka alphapapa [1] and reuses some ideas from there (namely,
fast element skipping via regexps).
[1] https://github.com/alphapapa/org-ql/
(org-element-at-point): The returned elements are now guaranteed to
have correct parents up to org-data. New optional argument
CACHED-ONLY limits element search to current cache---if element is not
in cache and current command is not in cache
`org-element--cache-non-modifying-commands', the cache is not updated
and the function returns nil. Also, support cache verification.
(org-element-at-point-no-context): New function. It is analogous of
older `org-element-at-point' with no guarantee that :parent properties
are correct beyond direct parent heading. This function does not
update cache and can be useful when cache updates should be avoided
for performance reasons.
* lisp/ob-core.el (org-babel-where-is-src-block-result): Support
section and org-data elements in cache.
* lisp/org-macro.el (org-macro-replace-all,
org-macro--find-keyword-value): Support org-element-cache.
* lisp/org-table.el (orgtbl-to-generic): Support org-element-cache.
* lisp/org.el (org-mode): Add cache persistance.
(org-up-element): Preserve old behaviour when error is returned for
section and org-data element.
*
testing/lisp/test-org-archive.el (test-org-archive/update-status-cookie):
Fix test when cache is active.
* testing/lisp/test-org-colview.el (test-org-colview/columns-update):
Fix test.
* testing/lisp/test-org-element.el (test-org-element/extract-element):
Add suport for new org-data element.
* testing/lisp/test-org-element.el (test-org-element/parent-property):
Fix equality check. Parents returned by cache and `org-element-map'
may not be `eq' now. Just `equal'.
* testing/lisp/test-org-element.el (test-org-element/context): Support
section and headline parents.
2021-10-16 13:17:10 +00:00
|
|
|
|
;; `:parent' property might change as we modify buffer.
|
|
|
|
|
;; We do not care about it when checking for circular
|
|
|
|
|
;; dependencies. So, setting `:parent' to nil making sure
|
|
|
|
|
;; that actual macro element (if org-element-cache is
|
|
|
|
|
;; active) is unchanged.
|
|
|
|
|
(setq macro (cl-copy-list macro))
|
|
|
|
|
(org-element-put-property macro :parent nil)
|
2018-07-07 10:45:40 +00:00
|
|
|
|
(let* ((key (org-element-property :key macro))
|
|
|
|
|
(value (org-macro-expand macro templates))
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(begin (org-element-begin macro))
|
2017-08-21 19:21:30 +00:00
|
|
|
|
(signature (list begin
|
|
|
|
|
macro
|
|
|
|
|
(org-element-property :args macro))))
|
|
|
|
|
;; Avoid circular dependencies by checking if the same
|
|
|
|
|
;; macro with the same arguments is expanded at the
|
|
|
|
|
;; same position twice.
|
|
|
|
|
(cond ((member signature record)
|
2018-07-07 10:45:40 +00:00
|
|
|
|
(error "Circular macro expansion: %s" key))
|
2017-08-21 19:21:30 +00:00
|
|
|
|
(value
|
|
|
|
|
(push signature record)
|
|
|
|
|
(delete-region
|
|
|
|
|
begin
|
|
|
|
|
;; Preserve white spaces after the macro.
|
2023-05-03 14:26:41 +00:00
|
|
|
|
(progn (goto-char (org-element-end macro))
|
2017-08-21 19:21:30 +00:00
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(point)))
|
|
|
|
|
;; Leave point before replacement in case of
|
|
|
|
|
;; recursive expansions.
|
|
|
|
|
(save-excursion (insert value)))
|
2018-07-07 10:45:40 +00:00
|
|
|
|
;; Special "results" macro: if it is not defined,
|
|
|
|
|
;; simply leave it as-is. It will be expanded in
|
|
|
|
|
;; a second phase.
|
|
|
|
|
((equal key "results"))
|
2017-11-21 21:25:17 +00:00
|
|
|
|
(t
|
2017-08-21 19:21:30 +00:00
|
|
|
|
(error "Undefined Org macro: %s; aborting"
|
|
|
|
|
(org-element-property :key macro))))))))))))
|
2013-02-16 13:03:59 +00:00
|
|
|
|
|
2015-01-20 23:25:47 +00:00
|
|
|
|
(defun org-macro-escape-arguments (&rest args)
|
|
|
|
|
"Build macro's arguments string from ARGS.
|
|
|
|
|
ARGS are strings. Return value is a string with arguments
|
|
|
|
|
properly escaped and separated with commas. This is the opposite
|
|
|
|
|
of `org-macro-extract-arguments'."
|
|
|
|
|
(let ((s ""))
|
|
|
|
|
(dolist (arg (reverse args) (substring s 1))
|
|
|
|
|
(setq s
|
|
|
|
|
(concat
|
|
|
|
|
","
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"\\(\\\\*\\),"
|
|
|
|
|
(lambda (m)
|
|
|
|
|
(concat (make-string (1+ (* 2 (length (match-string 1 m)))) ?\\)
|
|
|
|
|
","))
|
|
|
|
|
;; If a non-terminal argument ends on backslashes, make
|
|
|
|
|
;; sure to also escape them as they will be followed by
|
|
|
|
|
;; a comma.
|
|
|
|
|
(concat arg (and (not (equal s ""))
|
|
|
|
|
(string-match "\\\\+\\'" arg)
|
|
|
|
|
(match-string 0 arg)))
|
|
|
|
|
nil t)
|
|
|
|
|
s)))))
|
|
|
|
|
|
|
|
|
|
(defun org-macro-extract-arguments (s)
|
|
|
|
|
"Extract macro arguments from string S.
|
|
|
|
|
S is a string containing comma separated values properly escaped.
|
|
|
|
|
Return a list of arguments, as strings. This is the opposite of
|
|
|
|
|
`org-macro-escape-arguments'."
|
|
|
|
|
;; Do not use `org-split-string' since empty strings are
|
|
|
|
|
;; meaningful here.
|
|
|
|
|
(split-string
|
|
|
|
|
(replace-regexp-in-string
|
|
|
|
|
"\\(\\\\*\\),"
|
|
|
|
|
(lambda (str)
|
|
|
|
|
(let ((len (length (match-string 1 str))))
|
|
|
|
|
(concat (make-string (/ len 2) ?\\)
|
|
|
|
|
(if (zerop (mod len 2)) "\000" ","))))
|
|
|
|
|
s nil t)
|
|
|
|
|
"\000"))
|
|
|
|
|
|
2017-05-08 10:38:38 +00:00
|
|
|
|
|
|
|
|
|
;;; Helper functions and variables for internal macros
|
|
|
|
|
|
2018-07-07 10:37:24 +00:00
|
|
|
|
(defun org-macro--get-property (property location)
|
|
|
|
|
"Find PROPERTY's value at LOCATION.
|
|
|
|
|
PROPERTY is a string. LOCATION is a search string, as expected
|
|
|
|
|
by `org-link-search', or the empty string."
|
2023-12-15 12:52:07 +00:00
|
|
|
|
(org-with-wide-buffer
|
|
|
|
|
(when (org-string-nw-p location)
|
|
|
|
|
(condition-case _
|
|
|
|
|
(let ((org-link-search-must-match-exact-headline t))
|
|
|
|
|
(org-link-search location nil t))
|
|
|
|
|
(error
|
|
|
|
|
(error "Macro property failed: cannot find location %s" location))))
|
|
|
|
|
(org-entry-get nil property 'selective)))
|
2018-07-07 10:37:24 +00:00
|
|
|
|
|
2019-04-29 18:42:45 +00:00
|
|
|
|
(defun org-macro--find-keyword-value (name &optional collect)
|
2017-11-21 21:25:17 +00:00
|
|
|
|
"Find value for keyword NAME in current buffer.
|
2019-04-29 18:42:45 +00:00
|
|
|
|
Return value associated to the keywords named after NAME, as
|
|
|
|
|
a string, or nil. When optional argument COLLECT is non-nil,
|
|
|
|
|
concatenate values, separated with a space, from various keywords
|
|
|
|
|
in the buffer."
|
2017-11-21 21:25:17 +00:00
|
|
|
|
(org-with-point-at 1
|
|
|
|
|
(let ((regexp (format "^[ \t]*#\\+%s:" (regexp-quote name)))
|
|
|
|
|
(case-fold-search t)
|
|
|
|
|
(result nil))
|
2019-04-29 18:42:45 +00:00
|
|
|
|
(catch :exit
|
|
|
|
|
(while (re-search-forward regexp nil t)
|
Re-implement org-element-cache and add headline support
* lisp/org-element.el (org-element-with-disabled-cache): New macro.
(org-element-greater-elements): Add new org-data element. It
functions like a virtual headline containing the whole buffer. The
org-data properties are like headlie properties, but according to the
top-level drawer. org-data's category is the buffer's category as
defined by top-level property drawer, #+CATEGORY keyworsd, and the
buffer file name.
(org-element--cache-element-properties, org-element-set-element): New
variable containing properties to be transferred when updating changed
element in cache in `org-element-set-element'.
(org-element--get-node-properties): Allow parsing node propreties in
top-level drawer when new optional argument is passed. Respect
PROPERTY+ syntax.
(org-element--get-global-node-properties): New function. It returns
node properties for top-level property drawer.
(org-element-org-data-parser, org-element-org-data-interpreter):
Implement the new org-data element.
(org-element-headline-parser, org-element-section-parser): Add new
:robust-begin and :robust-end
properties delimiting safe changes that do not modify headline
element.
(org-element--list-struct): Fix cache update when adding a headline
inside list.
(org-element--current-element): Implement cache support. Record
parsing mode (:mode) and parsing granularity (:granularity) in the
element properties.
(org-element-parse-buffer, org-element--next-mode): Support new
org-data element.
(org-element--parse-elements): Record parsing granularity in the
returned tree
(org-element-use-cache): Enable cache by default.
(org-element-cache-persistent): New variable controlling cache
persistance across sessions. Enabled by default.
(org-element--cache-self-verify,
org-element--cache-self-verify-frequency,
org-element--cache-diagnostics, org-element--cache-map-statistics,
org-element--cache-map-statistics-threshold,
org-element--cache-diagnostics-level,
org-element--cache-diagnostics-ring,
org-element--cache-diagnostics-ring-size): New variables controlling
cache diagnostics and self-diagnostics. Greatly simplifies cache
debugging.
(org-element--cache, org-element--cache-sync-requests,
org-element--cache-sync-timer): Make cache buffer-local by default.
(org-element--headline-cache): Implement separate cache storing only
headlines and inlinetasks.
(org-element--cache-size, org-element--headline-cache-size): New
variables containing cache sizes. This is much faster than
`avl-tree-size'.
(org-element--cache-sync-requests): Update docstring explaning the
request list structure.
(org-element--cache-sync-keys-value): New variable replacing
`org-element--cache-sync-keys' hash table. The hash table was not
reliable because it was using elements as keys. Upon any cached
element update/shift, the keys were invalidated making cache ordering
incorrect and breaking the cache badly. Now, the cache keys are
stored as :org-element--cache-sync-key element property and the new
variable stores marker value indicating the current sync request
cycle. See `org-element--cache-key' for more details.
(org-element--cache-change-tic): New variable controlling buffer
modification count that is registered in cache. This variable allows
catching "stealth" edits.
(org-element--cache-non-modifying-commands): New variable listing
commands that will not be slown down if we fill cache on the fly.
(org-element--request-key, org-element--request-beg,
org-element--request-end, org-element--request-offset,
org-element--request-parent, org-element--request-phase): New macros.
They improve code readability (especially when using nameless-mode).
(org-element--format-element, org-element--cache-log-message,
org-element--cache-warn): New macros implementing generic logging
functionality.
(org-element--cache-key): Add section and org-data element support.
Change cache key storage from hash map to :org-element--cache-sync-key
element property + `org-element--cache-sync-keys-value'. We use the
latter to group all the cache keys during a single cache request
sequence. Once sync request is fully complete, the
`org-element--cache-sync-keys-value' is updated making all the old
sync keys obsolete (they will still be store as element properties).
(org-element--headline-cache-root): New function returning headline
cache root.
(org-element--cache-active-p): Prevent cache updates when
`inhibit-modification-hooks' is non-nil, unless non-nil optional
argument is provided.
(org-element--cache-find): Share cache between indirect buffers and
the base buffer. We have to do it because after-change hooks for
indirect buffer are not called in the base buffer and vice versa. Add
support for section and org-data elements.
(org-element--cache-put): Implement new approach for cache key
storage. Add diagnostics. Indicate cached elements using :cached
element property. Support cache size calculation.
(org-element--cache-remove): Invalidate parent contents when removing
element. Support cache size calculation. Detect cache corruption due
to misordered elements.
(org-element--cache-shift-positions): Support :robust-begin and
:robust-end element properties.
(org-element--cache-sync): Add diagnostics. Add detailed comments.
Prevent slowdown when large cache chunks need to be deleted forcing
O(N) complexity cutoff. In phase 2, fix cases when next request
contains deleted cache key. In phase 2, fix scenario when newly
inserted element intersects with existing elements in cache. In phase
2, detect obsolete parents removed from cache.
(org-element--open-end-p): New function checking if an element can
have blank lines right after its :contents-end.
(org-element--parse-to): Do not alter match data. Process complex
parsing mode changes correctly. Support headlines in cache. Support
org-data parsing. Add detailed comments. Add diagnostics.
(org-element--cache-sensitive-re): Make list lines sensitive.
(org-element--cache-change-warning): Update docstring. Now, the
variable can have t, nil, and number values. Numbers are used to
provide more details about changed headlines.
(org-element--cache-before-change, org-element--cache-after-change):
Handle headline hierarchy. Properly handle cache in indirect
buffers.
(org-element--cache-after-change): Update docstring clarifying the
return values. Add special handling for headline and org-data
elements updating them in-place instead of removing together with the
whole contents when possible. Use :robust-begin/:robust-end element
properties to detect robust changes.
(org-element--cache-submit-request): Add detailed comments. Correctly
handle cache in indirect buffers. Delegate element modifications to
`org-element--cache-for-removal'.
(org-element--cache-verify-element): New function for cache
self-verification.
(org-element--cache-persist-before-write,
org-element--cache-persist-before-read,
org-element--cache-persist-after-read): Implement cache persistance.
(org-element-cache-reset): Correctly handle cache in indirect
buffers. Support cache persistance. Support new cache size
calculation and new cache key schema.
(org-element-cache-map): New function analagous to `org-element-map',
but much faster. The function overperforms org-ql written by Adam
Porter aka alphapapa [1] and reuses some ideas from there (namely,
fast element skipping via regexps).
[1] https://github.com/alphapapa/org-ql/
(org-element-at-point): The returned elements are now guaranteed to
have correct parents up to org-data. New optional argument
CACHED-ONLY limits element search to current cache---if element is not
in cache and current command is not in cache
`org-element--cache-non-modifying-commands', the cache is not updated
and the function returns nil. Also, support cache verification.
(org-element-at-point-no-context): New function. It is analogous of
older `org-element-at-point' with no guarantee that :parent properties
are correct beyond direct parent heading. This function does not
update cache and can be useful when cache updates should be avoided
for performance reasons.
* lisp/ob-core.el (org-babel-where-is-src-block-result): Support
section and org-data elements in cache.
* lisp/org-macro.el (org-macro-replace-all,
org-macro--find-keyword-value): Support org-element-cache.
* lisp/org-table.el (orgtbl-to-generic): Support org-element-cache.
* lisp/org.el (org-mode): Add cache persistance.
(org-up-element): Preserve old behaviour when error is returned for
section and org-data element.
*
testing/lisp/test-org-archive.el (test-org-archive/update-status-cookie):
Fix test when cache is active.
* testing/lisp/test-org-colview.el (test-org-colview/columns-update):
Fix test.
* testing/lisp/test-org-element.el (test-org-element/extract-element):
Add suport for new org-data element.
* testing/lisp/test-org-element.el (test-org-element/parent-property):
Fix equality check. Parents returned by cache and `org-element-map'
may not be `eq' now. Just `equal'.
* testing/lisp/test-org-element.el (test-org-element/context): Support
section and headline parents.
2021-10-16 13:17:10 +00:00
|
|
|
|
(let ((element (org-with-point-at (match-beginning 0) (org-element-keyword-parser (line-end-position) (list (match-beginning 0))))))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(when (org-element-type-p element 'keyword)
|
2019-04-29 18:42:45 +00:00
|
|
|
|
(let ((value (org-element-property :value element)))
|
|
|
|
|
(if (not collect) (throw :exit value)
|
|
|
|
|
(setq result (concat result " " value)))))))
|
|
|
|
|
(and result (org-trim result))))))
|
2017-11-21 21:25:17 +00:00
|
|
|
|
|
2019-04-29 18:35:23 +00:00
|
|
|
|
(defun org-macro--find-date ()
|
|
|
|
|
"Find value for DATE in current buffer.
|
|
|
|
|
Return value as a string."
|
|
|
|
|
(let* ((value (org-macro--find-keyword-value "DATE"))
|
|
|
|
|
(date (org-element-parse-secondary-string
|
|
|
|
|
value (org-element-restriction 'keyword))))
|
|
|
|
|
(if (and (consp date)
|
|
|
|
|
(not (cdr date))
|
2023-05-16 10:41:53 +00:00
|
|
|
|
(org-element-type-p (car date) 'timestamp))
|
2019-04-29 18:35:23 +00:00
|
|
|
|
(format "(eval (if (org-string-nw-p $1) %s %S))"
|
2022-11-07 07:05:37 +00:00
|
|
|
|
(format "(org-format-timestamp '%S $1)"
|
2023-05-16 11:16:35 +00:00
|
|
|
|
(org-element-put-property
|
|
|
|
|
(org-element-copy (car date))
|
|
|
|
|
;; Remove non-printable.
|
|
|
|
|
:buffer nil))
|
2019-04-29 18:35:23 +00:00
|
|
|
|
value)
|
|
|
|
|
value)))
|
2017-11-21 21:25:17 +00:00
|
|
|
|
|
2016-05-18 09:23:46 +00:00
|
|
|
|
(defun org-macro--vc-modified-time (file)
|
2022-07-25 10:29:49 +00:00
|
|
|
|
(require 'vc) ; Not everything we need is autoloaded.
|
2016-05-18 09:23:46 +00:00
|
|
|
|
(save-window-excursion
|
|
|
|
|
(when (vc-backend file)
|
|
|
|
|
(let ((buf (get-buffer-create " *org-vc*"))
|
|
|
|
|
(case-fold-search t)
|
|
|
|
|
date)
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(progn
|
2021-10-24 02:18:07 +00:00
|
|
|
|
(vc-call print-log (list file) buf nil nil 1)
|
2016-05-18 09:23:46 +00:00
|
|
|
|
(with-current-buffer buf
|
|
|
|
|
(vc-exec-after
|
|
|
|
|
(lambda ()
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(when (re-search-forward "Date:?[ \t]*" nil t)
|
|
|
|
|
(let ((time (parse-time-string
|
|
|
|
|
(buffer-substring
|
|
|
|
|
(point) (line-end-position)))))
|
|
|
|
|
(when (cl-some #'identity time)
|
Use `org-encode-time' helper macro
* lisp/ol.el (org-store-link):
* lisp/org-agenda.el (org-agenda-get-timestamps)
(org-agenda-get-progress, agenda-bulk-action):
* lisp/org-capture.el (org-capture-fill-template):
* lisp/org-clock.el (org-clock-get-sum-start)
(org-clock-special-range, org-clocktable-shift)
(org-clocktable-steps):
* lisp/org-colview.el (org-colview-construct-allowed-dates):
* lisp/org-datetree.el (org-datetree-find-iso-week-create)
(org-datetree-insert-line):
* lisp/org-element.el (org-element-timestamp-interpreter):
* lisp/org-macro.el (org-macro--vc-modified-time):
* lisp/org-macs.el (org-matcher-time):
* lisp/org.el (org-current-time, org-current-effective-time)
(org-add-planning-info, org-read-date, org-read-date-display)
(org-read-date-analyze, org-eval-in-calendar)
(org-calendar-select, org-display-custom-time)
(org-calendar-select-mouse, org-time-string-to-time)
(org-time-from-absolute, org-at-clock-log-p)
(org-date-from-calendar, org-get-cursor-date)
(org-timestamp-to-time):
* testing/lisp/test-org-clock.el (org-test-clock-create-timestamp):
* lisp/ox-icalendar.el (org-icalendar-convert-timestamp):
Avoid direct calls of `encode-time', use `org-encode-time' instead.
Org supports Emacs-26, but the recommended way to call `encode-time'
changed in Emacs-27. In Emacs-29 DST and TZ elements of the single list
arguments became optional. In Org it is still convenient to call the
function with separate arguments without explicit DST and TZ arguments.
The `org-encode-time' should mitigate attempts to modernize Org code
directly in the Emacs repository.
2022-05-02 14:19:59 +00:00
|
|
|
|
(setq date (org-encode-time time))))))))
|
2016-05-18 09:23:46 +00:00
|
|
|
|
(let ((proc (get-buffer-process buf)))
|
|
|
|
|
(while (and proc (accept-process-output proc .5 nil t)))))
|
|
|
|
|
(kill-buffer buf))
|
|
|
|
|
date))))
|
|
|
|
|
|
2017-05-08 10:38:38 +00:00
|
|
|
|
(defvar org-macro--counter-table nil
|
|
|
|
|
"Hash table containing counter value per name.")
|
|
|
|
|
|
|
|
|
|
(defun org-macro--counter-initialize ()
|
|
|
|
|
"Initialize `org-macro--counter-table'."
|
|
|
|
|
(setq org-macro--counter-table (make-hash-table :test #'equal)))
|
|
|
|
|
|
2017-06-18 02:12:20 +00:00
|
|
|
|
(defun org-macro--counter-increment (name &optional action)
|
2017-05-08 10:38:38 +00:00
|
|
|
|
"Increment counter NAME.
|
2017-06-18 02:12:20 +00:00
|
|
|
|
NAME is a string identifying the counter.
|
|
|
|
|
|
|
|
|
|
When non-nil, optional argument ACTION is a string.
|
|
|
|
|
|
|
|
|
|
If the string is \"-\", keep the NAME counter at its current
|
|
|
|
|
value, i.e. do not increment.
|
|
|
|
|
|
|
|
|
|
If the string represents an integer, set the counter to this number.
|
|
|
|
|
|
|
|
|
|
Any other non-empty string resets the counter to 1."
|
2021-04-11 17:17:54 +00:00
|
|
|
|
(let ((name-trimmed (if (stringp name) (org-trim name) ""))
|
2017-06-18 02:12:20 +00:00
|
|
|
|
(action-trimmed (when (org-string-nw-p action)
|
|
|
|
|
(org-trim action))))
|
|
|
|
|
(puthash name-trimmed
|
|
|
|
|
(cond ((not (org-string-nw-p action-trimmed))
|
|
|
|
|
(1+ (gethash name-trimmed org-macro--counter-table 0)))
|
|
|
|
|
((string= "-" action-trimmed)
|
|
|
|
|
(gethash name-trimmed org-macro--counter-table 1))
|
|
|
|
|
((string-match-p "\\`[0-9]+\\'" action-trimmed)
|
|
|
|
|
(string-to-number action-trimmed))
|
|
|
|
|
(t 1))
|
|
|
|
|
org-macro--counter-table)))
|
2017-05-08 10:38:38 +00:00
|
|
|
|
|
2013-02-16 13:03:59 +00:00
|
|
|
|
(provide 'org-macro)
|
2020-02-18 21:57:37 +00:00
|
|
|
|
|
2013-02-16 13:03:59 +00:00
|
|
|
|
;;; org-macro.el ends here
|