emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [BUG] No font lock in src blocks for shells in org-babel-shell-names


From: Ihor Radchenko
Subject: Re: [BUG] No font lock in src blocks for shells in org-babel-shell-names (was Re: Font lock for org-babel shell scripts?)
Date: Tue, 04 Apr 2023 12:32:27 +0000

Derek Chen-Becker <derek@chen-becker.org> writes:

> I fiddled around a little bit this weekend and confirmed that this (sloppy)
> code makes highlighting work for all shell types that sh-script supports:
>
> ;;A quick hack to try and support more shells syntax highlight in org babel
> (require 'sh-script)
> (require 'ob-shell)
> (let ((shells (seq-filter (lambda (shell) (not (eq shell 'sh)))
> (flatten-tree sh-ancestor-alist))))

See the attached tentative patch.
>From 85e268de9435d94eb6766e3f92f4f56a9dc1aebe Mon Sep 17 00:00:00 2001
Message-Id: 
<85e268de9435d94eb6766e3f92f4f56a9dc1aebe.1680611510.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Tue, 4 Apr 2023 14:30:34 +0200
Subject: [PATCH] org-src: Use `sh-mode' for all the shells it can handle

* lisp/org-src.el (org-src--get-known-shells): New helper function
extracting known shells from `sh-ancestor-alist'.
(org-src-lang-modes): Update the value.

Link: 
CAMbmz5ntkOHMiZG4EbNAks9ob-0ahnciCfHQ9LQmJoci0+i7fg@mail.gmail.com">https://orgmode.org/list/CAMbmz5ntkOHMiZG4EbNAks9ob-0ahnciCfHQ9LQmJoci0+i7fg@mail.gmail.com
---
 lisp/org-src.el | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index ec2716885..2669b1b77 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -194,11 +194,17 @@ (defvar org-src-mode-hook nil
 or similar things which you want to have when editing a source code file,
 but which mess up the display of a snippet in Org exported files.")
 
+(defun org-src--get-known-shells ()
+  "List all the shells in `sh-ancestor-alist' for `org-src-lang-modes'.
+The shells are associated with `sh-mode'."
+  (mapcar
+   (lambda (shell) (cons (symbol-name shell) 'sh))
+   (delete-dups (flatten-tree sh-ancestor-alist))))
+
 (defcustom org-src-lang-modes
-  '(("C" . c)
+  `(("C" . c)
     ("C++" . c++)
     ("asymptote" . asy)
-    ("bash" . sh)
     ("beamer" . latex)
     ("calc" . fundamental)
     ("cpp" . c++)
@@ -208,9 +214,10 @@ (defcustom org-src-lang-modes
     ("elisp" . emacs-lisp)
     ("ocaml" . tuareg)
     ("screen" . shell-script)
-    ("shell" . sh)
     ("sqlite" . sql)
-    ("toml" . conf-toml))
+    ("toml" . conf-toml)
+    ("shell" . sh)
+    ,@(org-src--get-known-shells))
   "Alist mapping languages to their major mode.
 
 The key is the language name.  The value is the mode name, as
@@ -221,7 +228,7 @@ (defcustom org-src-lang-modes
 the user side.  For example, there is no `ocaml-mode' in Emacs,
 but the mode to use is `tuareg-mode'."
   :group 'org-edit-structure
-  :package-version '(Org . "9.6")
+  :package-version '(Org . "9.7")
   :type '(repeat
          (cons
           (string "Language name")
-- 
2.40.0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

reply via email to

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