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

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

[elpa] externals/lentic 97c01a0a02 310/333: First line fixup now works f


From: ELPA Syncer
Subject: [elpa] externals/lentic 97c01a0a02 310/333: First line fixup now works from org to lua/sh
Date: Tue, 27 Feb 2024 13:00:48 -0500 (EST)

branch: externals/lentic
commit 97c01a0a02fc462a30fdd1644d4ead2b884ffc0e
Author: Phillip Lord <phillip.lord@russet.org.uk>
Commit: Phillip Lord <phillip.lord@russet.org.uk>

    First line fixup now works from org to lua/sh
    
    We now make explicit use of the comment character to perform the first
    line fixup which was preventing org to lua/sh from working. Also, lua
    and sh config had comment-start, comment-stop backward.
---
 dev-resources/fulllua.lua  | 13 ++++++------
 dev-resources/fullsh.org   |  7 +++----
 dev-resources/fullsh.sh    |  7 +++----
 lentic-cookie.el           | 52 ++++++++++++++++++++--------------------------
 lentic-script.el           |  8 +++----
 test/lentic-cookie-test.el | 21 ++++++++++++++++++-
 test/lentic-script-test.el | 28 +++++++++++++++++++++++++
 7 files changed, 87 insertions(+), 49 deletions(-)

diff --git a/dev-resources/fulllua.lua b/dev-resources/fulllua.lua
index 37d95cd07e..2415ac3a8d 100644
--- a/dev-resources/fulllua.lua
+++ b/dev-resources/fulllua.lua
@@ -1,10 +1,9 @@
 #!/usr/bin/env lua
 
--- #+begin_src lua
--- print( "Hello World" )
--- #+end_src
+-- #+BEGIN_SRC lua
+print( "Hello World" )
+-- #+END_SRC
 
-
--- Local Variables:
--- lentic-init: lentic-lua-script-init
--- End:
+-- # Local Variables:
+-- # lentic-init: lentic-lua-script-init
+-- # End:
diff --git a/dev-resources/fullsh.org b/dev-resources/fullsh.org
index 6bab26f3d5..4dadf80bba 100644
--- a/dev-resources/fullsh.org
+++ b/dev-resources/fullsh.org
@@ -4,7 +4,6 @@
 echo "hello world"
 #+end_src
 
-
-Local Variables:
-lentic-init: lentic-bash-script-init
-End:
+# Local Variables:
+# lentic-init: lentic-bash-script-init
+# End:
diff --git a/dev-resources/fullsh.sh b/dev-resources/fullsh.sh
index cf00fe90da..f77f0c2208 100644
--- a/dev-resources/fullsh.sh
+++ b/dev-resources/fullsh.sh
@@ -4,7 +4,6 @@
 echo "hello world"
 ## #+end_src
 
-
-## Local Variables:
-## lentic-init: lentic-bash-script-init
-## End:
+## # Local Variables:
+## # lentic-init: lentic-bash-script-init
+## # End:
diff --git a/lentic-cookie.el b/lentic-cookie.el
index 1be423434a..e255fc8d3d 100644
--- a/lentic-cookie.el
+++ b/lentic-cookie.el
@@ -39,7 +39,8 @@
   :documentation "Configuration for a magic cookie containing
   lentic buffer that is not commented.")
 
-(defun lentic-cookie--uncommented-fixup-first-line-1 (buffer first-line-end)
+(defun lentic-cookie--uncommented-fixup-first-line-1 (buffer first-line-end
+                                                             comment)
   "Fixup the first line.
 
 BUFFER is the buffer.
@@ -51,8 +52,15 @@ despite the name of the function!"
    (m-buffer-replace-match
     (m-buffer-match
      buffer
-     (rx
-      (and line-start (0+ anything) "# #!"))
+     (rx-to-string
+      `(and line-start
+            (or
+             ;; the line may have been commented during the update
+             ,comment
+             ;; the line may have the comment from org-mode
+             "# ")
+            ;; and this is the actual start
+            "#!"))
      :end first-line-end)
     "#!")))
 
@@ -62,7 +70,8 @@ despite the name of the function!"
 CONF is the `lentic-configuration' object.
 FIRST-LINE-END is the location of the end of the line."
   (lentic-cookie--uncommented-fixup-first-line-1
-   (lentic-that conf) first-line-end))
+   (lentic-that conf) first-line-end
+   (oref conf :comment)))
 
 (defmethod lentic-clone
   ((conf lentic-cookie-uncommented-configuration)
@@ -71,30 +80,13 @@ FIRST-LINE-END is the location of the end of the line."
   (let ((clone-return
           (call-next-method conf start stop
                             length-before start-converted stop-converted)))
-    (if
-        (or
-         ;; next method has done strange things
-         (not clone-return)
-         ;; calling method is broad
-         (not start)
-         (not stop)
-         (m-buffer-with-markers
-             ((first-line
-               (m-buffer-match-first-line
-                (lentic-this conf))))
-           (or
-            (m-buffer-in-match-p
-             first-line start)
-            (m-buffer-in-match-p
-             first-line stop))))
-        (progn
-          (lentic-cookie-uncommented-fixup-first-line
-           conf
-           (cl-cadar
-            (m-buffer-match-first-line
-             (lentic-this conf)
-             :numeric t)))
-          nil)
+    (if (lentic-cookie-uncommented-fixup-first-line
+         conf
+         (cl-cadar
+          (m-buffer-match-first-line
+           (lentic-this conf)
+           :numeric t)))
+        nil
       clone-return)))
 
 (defclass lentic-cookie-commented-configuration
@@ -116,7 +108,9 @@ despite the name of the function!"
     (m-buffer-match
      buffer
      (rx
-      (and line-start "#!"))
+      (and line-start
+           (0+ anything)
+           "#!"))
      :end first-line-end)
     "# #!")))
 
diff --git a/lentic-script.el b/lentic-script.el
index 5d80495674..cd668c5052 100644
--- a/lentic-script.el
+++ b/lentic-script.el
@@ -80,8 +80,8 @@
    "temp"
    :this-buffer (current-buffer)
    :comment "## "
-   :comment-start "#\\\+BEGIN_SRC sh"
-   :comment-stop "#\\\+END_SRC"
+   :comment-stop "#\\\+BEGIN_SRC sh"
+   :comment-start "#\\\+END_SRC"
    :lentic-file
    (lentic-script-lentic-file)))
 
@@ -95,8 +95,8 @@
    "temp"
    :this-buffer (current-buffer)
    :comment "-- "
-   :comment-start "#\\\+BEGIN_SRC lua"
-   :comment-stop "#\\\+END_SRC"
+   :comment-stop "#\\\+BEGIN_SRC lua"
+   :comment-start "#\\\+END_SRC"
    :lentic-file
    (lentic-script-lentic-file)))
 
diff --git a/test/lentic-cookie-test.el b/test/lentic-cookie-test.el
index b6527bbdb2..0bfe3a9535 100644
--- a/test/lentic-cookie-test.el
+++ b/test/lentic-cookie-test.el
@@ -38,7 +38,8 @@
 ")
       (lentic-cookie--uncommented-fixup-first-line-1
        (current-buffer)
-       (point-max))
+       (point-max)
+       "## ")
       (buffer-substring-no-properties
        (point-min)
        (point-max)))
@@ -62,6 +63,24 @@
     "# #!/usr/bin/python
 ")))
 
+(ert-deftest lentic-cookie-test-commented-fixup-with-comments-in ()
+  (should
+   (assess=
+    (with-temp-buffer
+      (insert
+       "-- #!/usr/bin/lua
+")
+      (lentic-cookie--commented-fixup-first-line-1
+       (current-buffer)
+       (point-max))
+      (buffer-substring-no-properties
+       (point-min)
+       (point-max)))
+    "# #!/usr/bin/lua
+")))
+
+
+
 
 
 ;;; lentic-cookie-test.el ends here:
diff --git a/test/lentic-script-test.el b/test/lentic-script-test.el
index 9b68a7eb75..1a4c089dae 100644
--- a/test/lentic-script-test.el
+++ b/test/lentic-script-test.el
@@ -78,5 +78,33 @@
      "fulllua.lua"
      #'lentic-lua-script-init))))
 
+
+(ert-deftest lentic-script-lua-clone-change ()
+  (should
+   (lentic-test-clone-and-change=
+    #'lentic-lua-script-init
+    "fulllua.lua"
+    "fulllua.org"
+    (lambda ()
+      (forward-line)
+      (insert "-- hello")
+      (beginning-of-line)
+      (kill-line))))
+  (should
+   (lentic-test-clone-and-change=
+    #'lentic-lua-script-init
+    "fulllua.lua"
+    "fulllua.org"
+    nil
+    (lambda ()
+      (forward-line)
+      (insert "hello")
+      (beginning-of-line)
+      (kill-line))))
+  )
+
+
+
+
 (provide 'lentic-script-test)
 ;;; lentic-script-test.el ends here



reply via email to

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