Quellcode durchsuchen

org-src: New `org-src-get-lang-mode' function

* lisp/org-src.el (org-src-get-lang-mode): New function.
(org-src--get-lang-mode): Rename to `org-src-get-lang-mode'.
(org-src-font-lock-fontify-block):
(org-edit-latex-environment):
(org-edit-export-block):
(org-edit-src-code):
(org-edit-inline-src-code): Use new function.
Nicolas Goaziou vor 6 Jahren
Ursprung
Commit
c0218ea746
1 geänderte Dateien mit 14 neuen und 14 gelöschten Zeilen
  1. 14 14
      lisp/org-src.el

+ 14 - 14
lisp/org-src.el

@@ -301,15 +301,6 @@ Return nil if there is no such buffer."
 	     (eq (marker-buffer end) (marker-buffer org-src--end-marker))
 	     (eq (marker-buffer end) (marker-buffer org-src--end-marker))
 	     (throw 'exit b))))))
 	     (throw 'exit b))))))
 
 
-(defun org-src--get-lang-mode (lang)
-  "Return major mode that should be used for LANG.
-LANG is a string, and the returned major mode is a symbol."
-  (intern
-   (concat
-    (let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
-      (if (symbolp l) (symbol-name l) l))
-    "-mode")))
-
 (defun org-src--coordinates (pos beg end)
 (defun org-src--coordinates (pos beg end)
   "Return coordinates of POS relatively to BEG and END.
   "Return coordinates of POS relatively to BEG and END.
 POS, BEG and END are buffer positions.  Return value is either
 POS, BEG and END are buffer positions.  Return value is either
@@ -568,7 +559,7 @@ Leave point in edit buffer."
   "Fontify code block.
   "Fontify code block.
 This function is called by emacs automatic fontification, as long
 This function is called by emacs automatic fontification, as long
 as `org-src-fontify-natively' is non-nil."
 as `org-src-fontify-natively' is non-nil."
-  (let ((lang-mode (org-src--get-lang-mode lang)))
+  (let ((lang-mode (org-src-get-lang-mode lang)))
     (when (fboundp lang-mode)
     (when (fboundp lang-mode)
       (let ((string (buffer-substring-no-properties start end))
       (let ((string (buffer-substring-no-properties start end))
 	    (modified (buffer-modified-p))
 	    (modified (buffer-modified-p))
@@ -762,6 +753,15 @@ Org-babel commands."
     (org-src-do-at-code-block
     (org-src-do-at-code-block
      (call-interactively (lookup-key org-babel-map key)))))
      (call-interactively (lookup-key org-babel-map key)))))
 
 
+(defun org-src-get-lang-mode (lang)
+  "Return major mode that should be used for LANG.
+LANG is a string, and the returned major mode is a symbol."
+  (intern
+   (concat
+    (let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
+      (if (symbolp l) (symbol-name l) l))
+    "-mode")))
+
 (defun org-src-edit-buffer-p (&optional buffer)
 (defun org-src-edit-buffer-p (&optional buffer)
   "Non-nil when current buffer is a source editing buffer.
   "Non-nil when current buffer is a source editing buffer.
 If BUFFER is non-nil, test it instead."
 If BUFFER is non-nil, test it instead."
@@ -948,7 +948,7 @@ the LaTeX environment in the Org mode buffer."
     (org-src--edit-element
     (org-src--edit-element
      element
      element
      (org-src--construct-edit-buffer-name (buffer-name) "LaTeX environment")
      (org-src--construct-edit-buffer-name (buffer-name) "LaTeX environment")
-     (org-src--get-lang-mode "latex")
+     (org-src-get-lang-mode "latex")
      t)
      t)
     t))
     t))
 
 
@@ -973,7 +973,7 @@ Throw an error when not at an export block."
 			       ;; Missing export-block type.  Fallback
 			       ;; Missing export-block type.  Fallback
 			       ;; to default mode.
 			       ;; to default mode.
 			       "fundamental")))
 			       "fundamental")))
-	   (mode (org-src--get-lang-mode type)))
+	   (mode (org-src-get-lang-mode type)))
       (unless (functionp mode) (error "No such language mode: %s" mode))
       (unless (functionp mode) (error "No such language mode: %s" mode))
       (org-src--edit-element
       (org-src--edit-element
        element
        element
@@ -1006,7 +1006,7 @@ name of the sub-editing buffer."
     (let* ((lang
     (let* ((lang
 	    (if (eq type 'src-block) (org-element-property :language element)
 	    (if (eq type 'src-block) (org-element-property :language element)
 	      "example"))
 	      "example"))
-	   (lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang)))
+	   (lang-f (and (eq type 'src-block) (org-src-get-lang-mode lang)))
 	   (babel-info (and (eq type 'src-block)
 	   (babel-info (and (eq type 'src-block)
 			    (org-babel-get-src-block-info 'light)))
 			    (org-babel-get-src-block-info 'light)))
 	   deactivate-mark)
 	   deactivate-mark)
@@ -1039,7 +1039,7 @@ name of the sub-editing buffer."
 		 (org-src--on-datum-p context))
 		 (org-src--on-datum-p context))
       (user-error "Not on inline source code"))
       (user-error "Not on inline source code"))
     (let* ((lang (org-element-property :language context))
     (let* ((lang (org-element-property :language context))
-	   (lang-f (org-src--get-lang-mode lang))
+	   (lang-f (org-src-get-lang-mode lang))
 	   (babel-info (org-babel-get-src-block-info 'light))
 	   (babel-info (org-babel-get-src-block-info 'light))
 	   deactivate-mark)
 	   deactivate-mark)
       (unless (functionp lang-f) (error "No such language mode: %s" lang-f))
       (unless (functionp lang-f) (error "No such language mode: %s" lang-f))