Yesterday I wrote that I prefer putting each code snippet into its own dedicated file rather than into an org source block because "I don't want the code to execute with org-mode active."
What was I thinking; what does it mean?
Here's a scenario. I'm developing functions to create a document in some markup language. The colorizer function applies a color tag to the first word in a given string.
It works great in my Org source block. But when I add it to the lisp file and invoke it, it doesn't do exactly what I expect.
In Org mode, the single quote is a word constituent, which is fine for my purpose. However, in emacs-lisp-mode, single quote is a separator. The effect is demonstrated below. Note the code in the testre.el file tags only "Sophia," not "Sophia's," while the source block applies the tag as intended.
(defun colorizer (s) "Add blue color tag to first word in S." (interactive) (replace-regexp-in-string "\\(\\w+\\)\\(.+\\)" "blue{\\1}\\2" s t)) (defun testre () "Test colorizer." (interactive) (message (concat (colorizer "Blanche lives in Miami.") " " (colorizer "Sofia's sweater is yellow.")))) (testre) #+RESULTS: : blue{Blanche} lives in Miami. blue{Sofia’s} sweater is yellow.
Here's what the code in the testre.el file produces:
blue{Blanche} lives in Miami. blue{Sofia}’s sweater is yellow.
Another problem with having Org mode active in a lisp source block
is that indenting doesn't work as expected. Pressing C-M-\ does
nothing (if I'm lucky) or something undesirable. Once I activate
emacs-lisp-mode, C-M-\ makes the code look nice again. (If I
re-activate Org mode the buffer reloads, and I lose my place in
the document.) This makes sense when you recall that C-M-\ is
bound to indent-according-to-mode.
I'm sure I'm doing something wrong, or I have something misconfigured.
No comments:
Post a Comment
Thank you for taking time to comment. Please note that comments may be deleted if they:
* Contain link(s) to a domain outside USA or Canada or to a commercial enterprise.
* Include non-English words or characters.
* Are irrelevant to the subject matter of the post.
For posts older than 14 days, comments are moderated and require approval.