emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Lower-casing blocks and keywords


From: Kaushal Modi
Subject: Re: [O] Lower-casing blocks and keywords
Date: Fri, 02 Feb 2018 16:56:55 +0000

On Thu, Jan 25, 2018 at 3:17 PM Nicolas Goaziou <address@hidden> wrote:
> I also like the blocks and keywords to be lower-cased. I see this in the
> latest commit on master:
> https://code.orgmode.org/bzg/org-mode/commit/13424336a6f30c50952d291e7a82906c1210daf0
>
> Did you do that lower-casing by hand? Or do you have an elisp snippet or
> some script that does that?

IIRC, this was grep then eyeball and a macro to automatically convert
a line.

I got back to this task at hand, and this elisp command works just fine (based on export testing of a bunch of Org files).

Let me know if I missed out on something (or did over-lower-casing) :)

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

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

Inspiration:
https://code.orgmode.org/bzg/org-mode/commit/13424336a6f30c50952d291e7a82906c1210daf0."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (let ((case-fold-search nil)
          (count 0))
      ;; Match examples: "#+FOO bar", "#+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))))
--

Kaushal Modi


reply via email to

[Prev in Thread] Current Thread [Next in Thread]