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

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

[elpa] externals/lentic 2e290c74e3 207/333: Multiple oset added, and fac


From: ELPA Syncer
Subject: [elpa] externals/lentic 2e290c74e3 207/333: Multiple oset added, and factor constructors.
Date: Tue, 27 Feb 2024 13:00:35 -0500 (EST)

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

    Multiple oset added, and factor constructors.
    
    Add a new command for adding multiple properties at once. This allows me
    to factor our the multiple uses of the same settings in constructors. As
    the oset command also returns the object, I have also factored out many
    let bindings.
---
 lentic-asciidoc.el   |  48 ++++++++--------
 lentic-doc.el        |   1 -
 lentic-latex-code.el |  36 ++++++------
 lentic-org.el        | 158 ++++++++++++++++++++++-----------------------------
 lentic.el            |  18 ++++++
 5 files changed, 129 insertions(+), 132 deletions(-)

diff --git a/lentic-asciidoc.el b/lentic-asciidoc.el
index eac256a80c..6d2997f6ff 100644
--- a/lentic-asciidoc.el
+++ b/lentic-asciidoc.el
@@ -31,19 +31,26 @@
 ;;; Code:
 
 ;; #+begin_src emacs-lisp
+(require 'lentic)
 (require 'lentic-block)
 (require 'm-buffer)
+(require 'f)
 
-(defun lentic-asciidoc-commented-new ()
-  (lentic-commented-asciidoc-configuration
-   "lb-commented-clojure asciidoc"
+(defun lentic-asciidoc-oset (conf)
+  (lentic-m-oset
+   conf
    :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-           (buffer-file-name)) ".adoc")
    :comment ";; "))
 
+(defun lentic-asciidoc-commented-new ()
+  (lentic-asciidoc-oset
+   (lentic-commented-asciidoc-configuration
+    "lb-commented-clojure asciidoc"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name)) ".adoc"))))
+
 (defun lentic-clojure-asciidoc-init ()
   (lentic-asciidoc-commented-new))
 
@@ -51,14 +58,13 @@
              'lentic-clojure-asciidoc-init)
 
 (defun lentic-asciidoc-uncommented-new ()
-  (lentic-uncommented-asciidoc-configuration
-   "lb-uncommented-clojure-asciidoc"
-   :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name)) ".clj")
-   :comment ";; "))
+  (lentic-asciidoc-oset
+   (lentic-uncommented-asciidoc-configuration
+    "lb-uncommented-clojure-asciidoc"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name)) ".clj"))))
 
 ;;;###autoload
 (defun lentic-asciidoc-clojure-init ()
@@ -145,17 +151,13 @@ This should remove other \"....\" matches.
 
 (defmethod lentic-invert
   ((conf lentic-commented-asciidoc-configuration))
-  (let ((rtn
-         (lentic-asciidoc-uncommented-new)))
-    (oset rtn :that-buffer (lentic-this conf))
-    rtn))
+  (lentic-m-oset (lentic-asciidoc-uncommented-new)
+                 :that-buffer (lentic-this conf)))
 
 (defmethod lentic-invert
   ((conf lentic-uncommented-asciidoc-configuration))
-  (let ((rtn
-         (lentic-asciidoc-commented-new)))
-    (oset rtn :that-buffer (lentic-this conf))
-    rtn))
+  (lentic-m-oset (lentic-asciidoc-commented-new)
+                 :that-buffer (lentic-this conf)))
 
 (provide 'lentic-asciidoc)
 ;;; lentic-asciidoc.el ends here
diff --git a/lentic-doc.el b/lentic-doc.el
index 58a115b4cd..6027dce53b 100644
--- a/lentic-doc.el
+++ b/lentic-doc.el
@@ -32,7 +32,6 @@
 (require 'ox-html)
 (require 'browse-url)
 (require 'lentic)
-(require 'f)
 ;; #+end_src
 
 ;; ** Orgify Package
diff --git a/lentic-latex-code.el b/lentic-latex-code.el
index 8d6d84fd0e..037c585af0 100644
--- a/lentic-latex-code.el
+++ b/lentic-latex-code.el
@@ -41,18 +41,23 @@
 ;; #+begin_src emacs-lisp
 (require 'lentic-block)
 
-(defun lentic-clojure-to-latex-new ()
-  (lentic-commented-block-configuration
-   "lb-commented clojure latex"
+(defun lentic-latex-clojure-oset (conf)
+  (lentic-m-oset
+   conf
    :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name)) ".tex")
    :comment ";; "
    :comment-start "\\\\end{code}"
    :comment-stop "\\\\begin{code}"))
 
+(defun lentic-clojure-to-latex-new ()
+  (lentic-latex-clojure-oset
+   (lentic-commented-block-configuration
+    "lb-commented clojure latex"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name)) ".tex"))))
+
 ;;;###autoload
 (defun lentic-clojure-latex-init ()
   (lentic-clojure-to-latex-new))
@@ -62,16 +67,13 @@
 
 
 (defun lentic-latex-to-clojure-new ()
-  (lentic-uncommented-block-configuration
-   "lb-commented latex clojure"
-   :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name)) ".clj")
-   :comment ";; "
-   :comment-start "\\\\end{code}"
-   :comment-stop "\\\\begin{code}"))
+  (lentic-latex-clojure-oset
+   (lentic-uncommented-block-configuration
+    "lb-commented latex clojure"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name)) ".clj"))))
 
 ;;;###autoload
 (defun lentic-latex-clojure-init ()
diff --git a/lentic-org.el b/lentic-org.el
index bb82d9ef45..e666e1e269 100644
--- a/lentic-org.el
+++ b/lentic-org.el
@@ -71,42 +71,38 @@
 ;; the emacs-lisp mode lentic.
 
 ;; #+BEGIN_SRC emacs-lisp
-(defun lentic-org-to-el-new ()
-  (lentic-uncommented-block-configuration
-   "lb-org-to-el"
+(defun lentic-org-oset (conf)
+  (lentic-m-oset
+   conf
    :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name))
-    ".el")
    :comment ";; "
    :comment-stop "#\\\+BEGIN_SRC emacs-lisp"
    :comment-start "#\\\+END_SRC"))
 
 ;;;###autoload
 (defun lentic-org-el-init ()
-  (lentic-org-to-el-new))
+  (lentic-org-oset
+   (lentic-uncommented-block-configuration
+    "lb-org-to-el"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name))
+     ".el"))))
 
 (add-to-list 'lentic-init-functions
              'lentic-org-el-init)
 
-(defun lentic-el-to-org-new ()
-  (lentic-commented-block-configuration
-   "lb-el-to-org"
-   :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name))
-    ".org")
-   :comment ";; "
-   :comment-stop "#\\\+BEGIN_SRC emacs-lisp"
-   :comment-start "#\\\+END_SRC"))
-
 ;;;###autoload
 (defun lentic-el-org-init ()
-  (lentic-el-to-org-new))
+  (lentic-org-oset
+   (lentic-commented-block-configuration
+    "lb-el-to-org"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name))
+     ".org"))))
 
 (add-to-list 'lentic-init-functions
              'lentic-el-org-init)
@@ -303,28 +299,21 @@
 
 (defmethod lentic-invert
   ((conf lentic-org-to-orgel-configuration))
-  (let ((rtn
-         (lentic-orgel-to-org-new)))
-    (oset rtn :that-buffer
-          (lentic-this conf))
-    rtn))
-
-(defun lentic-org-to-orgel-new ()
-  (lentic-org-to-orgel-configuration
-   "lb-orgel-to-el"
-   :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name))
-    ".el")
-   :comment ";; "
-   :comment-stop "#\\\+BEGIN_SRC emacs-lisp"
-   :comment-start "#\\\+END_SRC"))
+  (lentic-m-oset
+   (lentic-orgel-org-init)
+   :that-buffer
+   (lentic-this conf)))
 
 ;;;###autoload
 (defun lentic-org-orgel-init ()
-  (lentic-org-to-orgel-new))
+  (lentic-org-oset
+   (lentic-org-to-orgel-configuration
+    "lb-orgel-to-el"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name))
+     ".el"))))
 
 (add-to-list 'lentic-init-functions
              'lentic-org-orgel-init)
@@ -364,52 +353,37 @@
 
 (defmethod lentic-invert
   ((conf lentic-orgel-to-org-configuration))
-  (let ((rtn
-         (lentic-org-to-orgel-new)))
-    (oset rtn :delete-on-exit t)
-    (oset rtn :that-buffer (lentic-this conf))
-    rtn))
-
-(defun lentic-orgel-to-org-new ()
-  (lentic-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
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name))
-    ".org")
-   :comment ";; "
-   :comment-stop "#\\\+BEGIN_SRC emacs-lisp"
-   :comment-start "#\\\+END_SRC"))
+  (lentic-m-oset
+   (lentic-org-orgel-init)
+   :delete-on-exit t
+   :that-buffer (lentic-this conf)))
 
 ;;;###autoload
 (defun lentic-orgel-org-init ()
-  (lentic-orgel-to-org-new))
+  (lentic-org-oset
+   (lentic-orgel-to-org-configuration
+    "lb-orgel-to-org"
+    ;; 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
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name))
+     ".org"))))
 
 (add-to-list 'lentic-init-functions
              'lentic-orgel-org-init)
 
 ;; #+END_SRC
 
-
-
-
 ;; *** org->clojure
 
 ;; #+BEGIN_SRC emacs-lisp
-(defun lentic-org-to-clojure-new ()
-  (lentic-uncommented-block-configuration
-   "lb-org-to-clojure"
+(defun lentic-org-clojure-oset (conf)
+  (lentic-m-oset
+   conf
    :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name))
-    ".clj")
    :comment ";; "
    :comment-stop "#\\\+BEGIN_SRC clojure"
    :comment-start "#\\\+END_SRC"
@@ -417,27 +391,30 @@
    ;; will be ignored. Probably we should count instead!
    :case-fold-search nil))
 
+;;;###autoload
 (defun lentic-org-clojure-init ()
-  (lentic-org-to-clojure-new))
+  (lentic-org-clojure-oset
+   (lentic-uncommented-block-configuration
+    "lb-org-to-clojure"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name))
+     ".clj"))))
 
 (add-to-list 'lentic-init-functions
              'lentic-org-clojure-init)
 
-(defun lentic-clojure-to-org-new ()
-  (lentic-commented-block-configuration
-   "lb-clojure-to-org"
-   :this-buffer (current-buffer)
-   :lentic-file
-   (concat
-    (file-name-sans-extension
-     (buffer-file-name))
-    ".org")
-   :comment ";; "
-   :comment-stop "#\\\+BEGIN_SRC clojure"
-   :comment-start "#\\\+END_SRC"))
-
+;;;###autoload
 (defun lentic-clojure-org-init ()
-  (lentic-clojure-to-org-new))
+  (lentic-org-clojure-oset
+   (lentic-commented-block-configuration
+    "lb-clojure-to-org"
+    :lentic-file
+    (concat
+     (file-name-sans-extension
+      (buffer-file-name))
+     ".org"))))
 
 (add-to-list 'lentic-init-functions
              'lentic-clojure-org-init)
@@ -454,4 +431,3 @@
 (provide 'lentic-org)
 ;;; lentic-org.el ends here
 ;; #+END_SRC
-
diff --git a/lentic.el b/lentic.el
index 50091dcdfc..cf1d49315d 100644
--- a/lentic.el
+++ b/lentic.el
@@ -273,6 +273,24 @@ or create it if it does not exist."
           "on"
         ""))))
 
+(defun lentic-m-oset (obj &rest plist)
+  "On OBJ set all properties in PLIST.
+Returns OBJ. See also `lentic-a-oset'"
+  (lentic-a-oset obj plist))
+
+(defun lentic-a-oset (obj plist)
+  "On OBJ, set all properties in PLIST.
+This is a utility function which just does the same as oset, but
+for lots of things at once. Returns OBJ."
+  (-map
+   (lambda (n)
+     (eieio-oset
+      obj
+      (car n)
+      (cadr n)))
+   (-partition 2 plist))
+  obj)
+
 ;; #+end_src
 
 ;; ** Default Configuration



reply via email to

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