Add a section on "Buffer properties" with tools to handle those.

This commit is contained in:
Gerard Vermeulen 2024-01-21 17:29:41 +01:00
parent dee56252fc
commit 0da38f0834
1 changed files with 54 additions and 0 deletions

View File

@ -2965,6 +2965,60 @@ to add =HTML+CSS+JS= for ~mhtml-mode~:
)
#+end_src
*** [[info:org#In-buffer Settings][Buffer properties]]
:PROPERTIES:
:CUSTOM_ID: sec:buffer-properties
:END:
#+caption[Buffer properties]:
#+caption: Buffer properties.
#+name: lst:buffer-properties
#+begin_src emacs-lisp -n
(with-eval-after-load 'org
(defconst prop-comments-link-re
"\\( :comments link$\\)\\|\\( *$\\)"
"Regexp to find \"#+property:\" \":comments link\".")
(defconst prop-ha-re-template
(format "\\(?:^[[:blank:]]*#\\+%s:[[:blank:]]+%s:%s\\+*\\)+"
"property" "header-args" "%s")
"Regexp template to find `#+property:' header-args:any-language.")
(defconst prop-emacs-lisp-ha-re
(format prop-ha-re-template "emacs-lisp")
"Regexp to find `#+property:' Emacs Lisp header arguments.")
(defconst prop-python-ha-re
(format prop-ha-re-template "python")
"Regexp to find `#+property:' Python header arguments.")
(defun prop-python-link-comments-toggle ()
(interactive)
(save-excursion
(goto-char (point-min))
(if (re-search-forward prop-python-ha-re nil 'noerror)
(if (re-search-forward prop-comments-link-re nil t)
(if (match-string 1)
(replace-match " ")
(replace-match " :comments link"))
(user-error "Found no python link comment"))
(user-error "Found no python header arguments property")))
(move-beginning-of-line 1)
(org-ctrl-c-ctrl-c))
(defun org-get-buffer-properties ()
"Get all properties in buffer."
(org-element-map (org-element-parse-buffer) 'keyword
(lambda (el)
(and ;; Use (upcase "property"), else it fails.
(string= (org-element-property :key el) "PROPERTY")
(let* ((strings (split-string (org-element-property :value el)))
(value (string-join (cdr strings) " "))
(name (car strings)))
(cons name value)))))))
#+end_src
*** [[info:org#Column View][Column View (info)]] and [[info:org#Property Syntax][Property Syntax (info)]]
:PROPERTIES:
:CUSTOM_ID: sec:using-properties