emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/lentic bfebaa4997 058/333: Support for orgel files.


From: ELPA Syncer
Subject: [elpa] externals/lentic bfebaa4997 058/333: Support for orgel files.
Date: Tue, 27 Feb 2024 13:00:02 -0500 (EST)

branch: externals/lentic
commit bfebaa499732fed67dcb78e850d31bf538b495bc
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>

    Support for orgel files.
    
    The previous org->el translation was very simple. This version restricts
    the structure of the org file that can be used, but provides a more
    complete translation. So ";;; Headers" are translated into "* Headers".
---
 dev-resources/orgel-org.el  |   9 ++++
 dev-resources/orgel-org.org |   9 ++++
 linked-buffer-org.el        | 103 ++++++++++++++++++++++++++++++++++++++++++++
 test/linked-buffer-test.el  |  15 ++++++-
 4 files changed, 134 insertions(+), 2 deletions(-)

diff --git a/dev-resources/orgel-org.el b/dev-resources/orgel-org.el
new file mode 100644
index 0000000000..2f3140a8ec
--- /dev/null
+++ b/dev-resources/orgel-org.el
@@ -0,0 +1,9 @@
+;;; orgel-org.el --- A test file -*- lexical-binding: t -*-
+
+;; Author: Phillip Lord
+
+;;; Commentary:
+
+;; #+BEGIN_SRC emacs-lisp
+(defun orgel-function ())
+;; #+END_SRC
diff --git a/dev-resources/orgel-org.org b/dev-resources/orgel-org.org
new file mode 100644
index 0000000000..f1130f136a
--- /dev/null
+++ b/dev-resources/orgel-org.org
@@ -0,0 +1,9 @@
+# # orgel-org.el --- A test file -*- lexical-binding: t -*-
+
+Author: Phillip Lord
+
+* Commentary
+
+#+BEGIN_SRC emacs-lisp
+(defun orgel-function ())
+#+END_SRC
diff --git a/linked-buffer-org.el b/linked-buffer-org.el
index 388c6bafb4..8013c8d29f 100644
--- a/linked-buffer-org.el
+++ b/linked-buffer-org.el
@@ -38,6 +38,7 @@
 
 ;;; Code:
 
+;; Simple org to el with nothing special
 (defun linked-buffer-org-to-el-new ()
   (linked-buffer-uncommented-block-configuration
    "lb-org-to-el"
@@ -72,5 +73,107 @@
   (setq linked-buffer-config
         (linked-buffer-el-to-org-new)))
 
+
+;; this is the more complex stuff for orgel
+;; which treats ;;; comments specially
+(defclass linked-buffer-org-to-orgel-configuration
+  (linked-buffer-uncommented-block-configuration)
+  ())
+
+(defmethod linked-buffer-clone
+  ((conf linked-buffer-org-to-orgel-configuration))
+  ;; do everything else to the buffer
+  (call-next-method conf)
+  (m-buffer-replace-match
+   (m-buffer-match
+    (linked-buffer-that conf)
+    ";; # # "
+    :end
+    (cadr
+     (car
+      (m-buffer-match-line
+       (linked-buffer-that conf)))))
+   ";;; ")
+  ;; replace big headers
+  (m-buffer-replace-match
+   (m-buffer-match (linked-buffer-that conf)
+                   "^;; [*] \\(\\\w*\\)")
+   ";;; \\1:"))
+
+(defmethod linked-buffer-invert
+  ((conf linked-buffer-org-to-orgel-configuration))
+  (let ((rtn
+         (linked-buffer-orgel-to-org-new)))
+    (oset rtn :that-buffer
+          (linked-buffer-this conf))
+    rtn))
+
+(defun linked-buffer-org-to-orgel-new ()
+  (linked-buffer-org-to-orgel-configuration
+   "lb-orgel-to-el"
+   :this-buffer (current-buffer)
+   :linked-file
+   (concat
+    (file-name-sans-extension
+     (buffer-file-name))
+    ".el")
+   :comment ";; "
+   :comment-stop "#\\\+BEGIN_SRC emacs-lisp"
+   :comment-start "#\\\+END_SRC"))
+
+(defun linked-buffer-org-orgel-init ()
+  (setq linked-buffer-config
+        (linked-buffer-org-to-orgel-new)))
+
+(defclass linked-buffer-orgel-to-org-configuration
+  (linked-buffer-commented-block-configuration)
+  ())
+
+(defmethod linked-buffer-clone
+  ((conf linked-buffer-orgel-to-org-configuration))
+  ;; do everything else to the buffer
+  (call-next-method conf)
+  (m-buffer-replace-match
+   (m-buffer-match
+    (linked-buffer-that conf)
+    ";;; "
+    :end
+    (cadr
+     (car
+      (m-buffer-match-line
+       (linked-buffer-that conf)))))
+   "# # ")
+  (m-buffer-replace-match
+   (m-buffer-match (linked-buffer-that conf) 
+                   "^;;; \\(\\\w*\\):")
+   "* \\1"))
+
+(defmethod linked-buffer-invert
+  ((conf linked-buffer-orgel-to-org-configuration))
+  (let ((rtn
+         (linked-buffer-org-to-orgel-new)))
+    (oset rtn :that-buffer (linked-buffer-this conf))
+    rtn))
+
+(defun linked-buffer-orgel-to-org-new ()
+  (linked-buffer-orgel-to-org-configuration
+   "lb-orgel-to-org"
+   :this-buffer (current-buffer)
+   ;; we don't really need a file and could cope without, but org mode assumes
+   ;; that the buffer is file name bound when it exports. As it happens, this
+   ;; also means that file saving is possible which in turn saves the el file
+   :linked-file
+   (concat
+    (file-name-sans-extension
+     (buffer-file-name))
+    ".org")
+   :comment ";; "
+   :comment-stop "#\\\+BEGIN_SRC emacs-lisp"
+   :comment-start "#\\\+END_SRC"))
+
+(defun linked-buffer-orgel-org-init ()
+  (setq linked-buffer-config
+        (linked-buffer-orgel-to-org-new)))
+
 (provide 'linked-buffer-org)
 ;;; linked-buffer-org.el ends here
diff --git a/test/linked-buffer-test.el b/test/linked-buffer-test.el
index f8a582f000..74f4b289cb 100644
--- a/test/linked-buffer-test.el
+++ b/test/linked-buffer-test.el
@@ -1,4 +1,3 @@
-
 (require 'linked-buffer)
 (require 'linked-buffer-latex-code)
 (require 'linked-buffer-asciidoc)
@@ -26,7 +25,6 @@
    (linked-buffer-batch-clone-with-config
     (linked-buffer-test-file file) init)))
 
-
 (defvar conf-default
   (linked-buffer-default-configuration "bob"))
 
@@ -69,3 +67,16 @@
    (linked-buffer-test-clone-equal
     'linked-buffer-el-org-init
     "el-org.el" "el-org.org")))
+
+(ert-deftest linked-buffer-orgel-org ()
+  (should
+   (linked-buffer-test-clone-equal
+    'linked-buffer-orgel-org-init
+    "orgel-org.el" "orgel-org.org")))
+
+;; Use this to generate a new test file
+
+;; (linked-buffer-batch-clone-and-save-with-config
+;;    "../dev-resources/orgel-org.el"
+;;    'linked-buffer-orgel-org-init
+;;  )



reply via email to

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