Emacs, scripting and anything text oriented.

Converting Org keywords to lower-case

Kaushal Modi

I never quite liked the trend to have upper-cased keywords in Org documents, like #+TITLE.

So it was a pleasure to see that trend start changing in this Org commit.. so that that same keyword would now be written as #+title.

But now I have quite a few Org documents with the ALL-CAPS keywords and block identifiers. So I came up with this little “lower-case all the Org keywords and block identifiers in the current document” Elisp command:

(defun modi/lower-case-org-keywords ()
  "Lower case Org keywords and block identifiers.

Example: \"#+TITLE\" -> \"#+title\"
         \"#+BEGIN_EXAMPLE\" -> \"#+begin_example\"

    (goto-char (point-min))
    (let ((case-fold-search nil)
          (count 0))
      ;; Match examples: "#+FOO bar", "#+FOO:", "=#+FOO=", "~#+FOO~",
      ;;                 "‘#+FOO’", "“#+FOO”", ",#+FOO bar",
      ;;                 "#+FOO_bar<eol>", "#+FOO<eol>".
      (while (re-search-forward "\\(?1:#\\+[A-Z_]+\\(?:_[[:alpha:]]+\\)*\\)\\(?:[ :=~’”]\\|$\\)" nil :noerror)
        (setq count (1+ count))
        (replace-match (downcase (match-string-no-properties 1)) :fixedcase nil nil 1))
      (message "Lower-cased %d matches" count))))

Here are few examples where M-x modi/lower-case-org-keywords did hundreds of replacements for me, saving me a lot of time 😎.


If you have written a response to this, enter your response post's URL below.

Or, you can send a "comment" webmention (it's OK if you don't know what that means). When asked about your website on an IndieAuth login screen, simply type https://commentpara.de.

Markdown Support**bold**, _italics_, ~~strikethrough~~, [descr](link), `monospace`, ```LANG\nline1\nline2\n``` (Yep, multi-line code blocks too, with syntax highlighting!), auto-hyperlinking.

Webmentions #

Comment by Kaushal Modi on Sun Sep 30, 2018 17:08 EDT


I’m glad you found it useful.

Is there also some setting to have these keywords in lowercase for the various export templates?

I didn’t get the reference to export templates. If you meant the Easy Templates, then you can just change the templates to expand to lower case keywords in your Emacs config.

Comment by doolio on Sun Sep 30, 2018 12:08 EDT
Thank you for this. Is there also some setting to have these keywords in lowercase for the various export templates?
Mentioned by Cole Lyman on Fri Aug 24, 2018 17:49 EDT

👍: https://scripter.co/org-keywords-lower-case/ super helpful, I didn’t realize that Org keywords can now be lowercase! This was one of my pet peeves with Org Mode when I first encountered it. Thanks @kaushalmodi!

Mentioned by Org Mode on Tue Jun 19, 2018 09:56 EDT
"Converting Org keywords to lower-case," scripter.co/org-keywords-l…