Re: Different comment syntaxes in within the same buffer?

Jean Louis <[email protected]>
Newsgroups gmane.emacs.help
Organization GNU Support
Message-ID <[email protected]>
On 2026-04-11 18:58, Basile Starynkevitch wrote:
> Look perhaps into Emacs support of literate programming like
> https://www.cs.tufts.edu/~nr/noweb/

Yes, noweb is fundamentally a filter: it reads a literate program source 
file (containing documentation and named code chunks) and filters it 
through two separate outputs — one for documentation (e.g., LaTeX, HTML, 
troff) and one for tangling code into executable source files — making 
it a classic text-filtering tool.

I remember back in time I had to do some patching to support Lisp or 
Elisp, I may be wrong.

In my environment I am heavily using RCD Template Interpolation System 
for Emacs:
https://hyperscope.link/3/7/1/3/3/RCD-Template-Interpolation-System-for-Emacs.html

The concept of template interpolation can be used to make any file 
edited by Emacs a "literate program" as it is about pre-filtering. Of 
course it needs adjustments for it to work.

My favorite and fastest markdown (Discount) doesn't have that nice 
syntax highlighting. So I have used pre-filtering this way:

◄Lisp

(defun shell-double-quote (s)
   "Double quotes for the string that shall be fed to shell command"
   (replace-regexp-in-string "\"" "\\\\\"" s))

(defun ffmpeg-cut-dired ()
   "Dired function to cut video files from specific begin time for
specific duration. You can cut many files at once if marked, or
the function will work only on the specific file. Customize the
list of video extensions below."
   (interactive)
   (let* ((files (dired-get-marked-files))
	 (allowed-extensions '("mp4" "ogv" "3gp")))
     (dolist (file files)
       (let* ((file-sans-ext (file-name-sans-extension file))
	     (file-ext (file-name-extension file)))
	(when (seq-contains allowed-extensions file-ext)
	  (let* ((output (concat file-sans-ext "-cut." file-ext))
		 (begin-time (read-from-minibuffer "Begin time in format 00:00:00: " 
"00:00:00"))
		 (duration (read-from-minibuffer "Duration in format 00:00:00: " 
"00:00:10"))
		 (command (format "ffmpeg -i \"%s\" -ss %s -t %s -async 1 \"%s\""
				  (shell-double-quote file)
				  begin-time duration
				  (shell-double-quote output))))
	    (shell-command command)))))))

►

then I get result with syntax highlighting as in the screenshot 
attached.

Now imagine how it can replace noweb:

- comment any code as you wish for literate programming; in any markup 
language;

- pre-filter, create your documentation; basically, pre-filter would 
inverse it, show the text, and fence the code; markup conversion can be 
to any file;

- when you wish to execute, it has to be pre-filtered. In my case it is 
text file in markdown format, that is pre-filtered, it shows syntax 
highlighted code, and then it converts finally to HTML by using Discount 
markdown. It is instant.

It uses "highlight" and supports so many languages.

Same principle can be used to make any file "literate". Any comments can 
be exported to LaTeX, PDF, HTML with fenced code, or commented by the 
language rules, or removed.

By having universal pre-layer, every kind of text becomes similar to Org 
Babel.

-- 
Jean Louis
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.