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

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

[elpa] externals/eev cd73535e74: Many changes in eev-kla.el.


From: ELPA Syncer
Subject: [elpa] externals/eev cd73535e74: Many changes in eev-kla.el.
Date: Fri, 18 Nov 2022 23:57:34 -0500 (EST)

branch: externals/eev
commit cd73535e74bd6baa9bf1bd2ddf608619a4927a7a
Author: Eduardo Ochs <eduardoochs@gmail.com>
Commit: Eduardo Ochs <eduardoochs@gmail.com>

    Many changes in eev-kla.el.
---
 .dir-locals.el |  14 --
 ChangeLog      |  30 ++++
 VERSION        |   4 +-
 eev-elinks.el  |  11 +-
 eev-flash.el   |  21 +--
 eev-intro.el   |  90 +++++++++-
 eev-kla.el     | 551 ++++++++++++++++++++++++---------------------------------
 7 files changed, 365 insertions(+), 356 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
deleted file mode 100644
index ed831664f0..0000000000
--- a/.dir-locals.el
+++ /dev/null
@@ -1,14 +0,0 @@
-;; This file:
-;;   http://angg.twu.net/eev-current/.dir-locals.el.html
-;;   http://angg.twu.net/eev-current/.dir-locals.el
-;;           (find-angg "eev-current/.dir-locals.el")
-;;                        (find-eev ".dir-locals.el")
-;; Author: Eduardo Ochs <eduardoochs@gmail.com>
-;; Public domain.
-;;
-;; See: (find-eev "eev-kla.el" "intro")
-;;      (find-enode "Directory Variables")
-;;      (find-enode "Directory Variables" "a subdirectory (a string)")
-;;
-(("" . ((nil . ((ee-preferred-c . "eev")))))
- )
diff --git a/ChangeLog b/ChangeLog
index d30369b1a4..db4721f0bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2022-11-19  Eduardo Ochs  <eduardoochs@gmail.com>
+
+       * eev-intro.el (find-kla-intro): several new sections.
+
+       * eev-kla.el (ee-kl-link-to-string-with-comment): new function.
+       (ee-kla2-bol): renamed to `ee-kla2-goto-bol'.
+
+2022-11-18  Eduardo Ochs  <eduardoochs@gmail.com>
+
+       * eev-kla.el (ee-kl-transforms): new variable.
+       (ee-kl-transform): new function.
+       (ee-kl-expand): use `ee-kl-transform'.
+       (ee-kl-format2-for-mode): deleted.
+       (ee-kl-comment-prefix): new function.
+       (ee-kl-insert): rewritten.
+       (ee-kl-format1, ee-kl-format2, ee-preferred-c)
+       (ee-preferred-c-guess): all these variables were deleted.
+       (ee-kl-format1): deleted this function.
+       (ee-kl-kill): don't call `ee-kl-format1' - always add a newline.
+       (ee-kl-sexp-to-string): deleted.
+       (ee-kl-lrcds, ee-kl-lrcd, ee-kl-r, ee-kl-c, ee-kl-d)
+       (ee-kl-shortfname, ee-kl-shorterfname, ee-kl-find-c)
+       (ee-kl-find-cfile, ee-kl-sexp-kla, ee-kl-sexp-klas)
+       (ee-kl-sexp-klf, ee-kl-sexp-klfs, ee-kl-sexp-klt): rewritten to
+       support nils.
+
+2022-11-17  Eduardo Ochs  <eduardoochs@gmail.com>
+
+       * eev-elinks.el (ee-remove-prefix): return nil when not a prefix.
+
 2022-11-16  Eduardo Ochs  <eduardoochs@gmail.com>
 
        * eev-kla.el (ee-kl-all-eds-for, ee-kl-best-ed-for)
diff --git a/VERSION b/VERSION
index ce88ea6584..2bef090546 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-Wed Nov 16 23:47:58 GMT 2022
-Wed Nov 16 20:47:58 -03 2022
+Sat Nov 19 03:58:17 GMT 2022
+Sat Nov 19 00:58:17 -03 2022
diff --git a/eev-elinks.el b/eev-elinks.el
index 879bd807c7..92584a0c54 100644
--- a/eev-elinks.el
+++ b/eev-elinks.el
@@ -19,7 +19,7 @@
 ;;
 ;; Author:     Eduardo Ochs <eduardoochs@gmail.com>
 ;; Maintainer: Eduardo Ochs <eduardoochs@gmail.com>
-;; Version:    20220906
+;; Version:    20221117
 ;; Keywords:   e-scripts
 ;;
 ;; Latest version: <http://angg.twu.net/eev-current/eev-elinks.el>
@@ -678,6 +678,11 @@ a hack to let use use `M-h M-i' for both \"intro\" and 
\"info\"."
 ;; This is a trick to make `find-file-links' generate short hyperlinks.
 ;; See: (find-eev-quick-intro "10.1. Generating short hyperlinks to files")
 ;;
+;; Note that this code is very old and uses only very basic Lisp
+;; functions. The functions in eev-kla.el do something similar to
+;; this, but using cl-loop. See:
+;;   (find-kla-intro)
+;;
 ;; Each call to `(code-c-d C D)' generates an entry `(C D)' in the
 ;; alist `ee-code-c-d-pairs'. Try:
 ;;
@@ -772,7 +777,9 @@ CODE is evaluated inside a `let' that sets the variables 
`c',
 
 (defun ee-remove-prefix (prefix str)
   "Example: (ee-remove-prefix \"ab\" \"abcde\") --> \"cde\""
-  (substring str (length prefix)))
+  (and (<= (length prefix) (length str))
+       (equal prefix (substring str 0 (length prefix)))
+       (substring str (length prefix))))
 
 (defun ee-replace-prefix0 (prefix newprefix fname)
   (if (ee-prefixp prefix fname)
diff --git a/eev-flash.el b/eev-flash.el
index 9eeb22bfd6..e52b1b5e9b 100644
--- a/eev-flash.el
+++ b/eev-flash.el
@@ -35,15 +35,9 @@
 ;; (find-eev "eev-eval.el")
 ;; (find-eev "eev-bounded.el")
 
+;; «.specs»    (to "specs")
+;; «.eeflash»  (to "eeflash")
 
-;; New version - with a `-' because it is non-interactive, and
-;; consequently an internal function.
-
-(defun ee-flash (start end &optional face duration)
-  "Highlight the region between START and END using FACE, for time DURATION."
-  (let ((ovl (make-overlay start end)))
-    (overlay-put ovl 'face (or face 'region))
-    (run-at-time (or duration 1) nil 'delete-overlay ovl)))
 
 
 
@@ -52,11 +46,12 @@
 ;; To do: delete most of this, use just `ee-flash' instead.
 ;; Drop the idea of flash-specs as lists.
 
+;; «specs»  (to ".specs")
 ;; (setq eeb-highlight-spec '(highlight 0.2))
 (defvar ee-highlight-spec  '(highlight 0.75)) ; to do: rename highlight->flash
 (defvar eeb-highlight-spec '(highlight 0.5))
 (defvar eek-highlight-spec '(region 0.75))
-(defvar eeflash-default '(highlight 0.5))
+(defvar eeflash-default    '(highlight 0.5))
 
 
 ;;;             __ _           _     
@@ -66,7 +61,13 @@
 ;;;  \___|\___|_| |_|\__,_|___/_| |_|
 ;;;                                  
 ;;; temporary highlighting (flashing)
-;;;
+;; «eeflash»  (to ".eeflash")
+
+(defun ee-flash (start end &optional face duration)
+  "Highlight the region between START and END using FACE, for time DURATION."
+  (let ((ovl (make-overlay start end)))
+    (overlay-put ovl 'face (or face 'region))
+    (run-at-time (or duration 1) nil 'delete-overlay ovl)))
 
 (defun eeflash (start end &optional face duration)
   "Highlight the region between START and END using FACE, for time DURATION."
diff --git a/eev-intro.el b/eev-intro.el
index 224b0b6320..979a4f8c69 100644
--- a/eev-intro.el
+++ b/eev-intro.el
@@ -19,7 +19,7 @@
 ;;
 ;; Author:     Eduardo Ochs <eduardoochs@gmail.com>
 ;; Maintainer: Eduardo Ochs <eduardoochs@gmail.com>
-;; Version:    20221115
+;; Version:    20221119
 ;; Keywords:   e-scripts
 ;;
 ;; Latest version: <http://angg.twu.net/eev-current/eev-intro.el>
@@ -14780,14 +14780,96 @@ instead of `collect', like this:
 
 
 
-
-
 6. `cl-defun'
 =============
-See:
+Some functions in eev-kla.el are defined with `cl-defun' to make
+them easy to test. If you execute this `cl-defun',
+
+  (cl-defun foo
+    (&key a
+          (b 2)
+          (c (* b 10)))
+    (list a b c))
+
+this defines a function that can be called with the arguments
+`a', `b', and `c' given in any order. Try:
+
+  (foo :a 4 :b 5 :c 6)
+  (foo :c 70 :b 80 :a 90)
+
+These \":keyword-value\" pairs can also be omitted. The
+
+    (&key a
+          (b 2)
+          (c (* b 10)))
+
+means:
+
+  1. when there isn't a pair `:a value-for-a', then set a to nil,
+  2. when there isn't a pair `:b value-for-b', then set b to 2,
+  3. when there isn't a pair `:c value-for-c', then set 3 to the
+     result of (* b 10).
+
+Try:
+
+  (foo               )
+  (foo           :c 6)
+  (foo      :b 5     )
+  (foo      :b 5 :c 6)
+  (foo :a 4          )
+  (foo :a 4      :c 6)
+  (foo :a 4 :b 5     )
+  (foo :a 4 :b 5 :c 6)
+
+The keyword arguments for `cl-defun' are explained here:
 
   (find-clnode \"Argument Lists\" \"cl-defun\")
   (find-clnode \"Argument Lists\" \"&key ((KEYWORD VAR) INITFORM SVAR)\")
+  (find-clnode \"Argument Lists\" \"&key c d (e 17)\")
+
+
+
+7. The default `c', `d', and `r'
+================================
+The functions `ee-kl-c', `ee-kl-d', and `ee-kl-r' are defined here:
+
+  (find-eev \"eev-kla.el\" \"ee-kl-r-c-d\")
+
+If they receive a `fname' they convert it to an `l-r-c-d' using
+the ideas in sections 3 and 4, and then they extract the `r', the
+`c', and the `d' from the `l-r-c-d'. If they don't receive a
+`fname' they use this as the default:
+
+  (find-eev \"eev-kla.el\" \"default-args\")
+  (find-eev \"eev-kla.el\" \"default-args\" \"(defun ee-kl-fname\")
+
+
+
+8. The functions that generate sexps
+====================================
+Try these tests:
+
+  (ee-kl-lrcd       :fname \"/tmp/FOO/BAR/PLIC/bletch\")
+  (ee-kl-c          :fname \"/tmp/FOO/BAR/PLIC/bletch\")
+  (ee-kl-r          :fname \"/tmp/FOO/BAR/PLIC/bletch\")
+  (ee-kl-find-cfile :fname \"/tmp/FOO/BAR/PLIC/bletch\")
+  (ee-kl-find-cfile :c \"plic\")
+  (ee-kl-sexp-klf   :fname \"/tmp/FOO/BAR/PLIC/bletch\")
+
+
+
+
+9. Symlinks
+===========
+See: (find-eev \"eev-kla.el\" \"ee-kl-expand\")
+
+
+
+10. Aliases
+===========
+See: (find-eev \"eev-kla.el\" \"aliases\")
+
+
   (find-eev \"eev-kla.el\" \"other-defaults\")
 
   (find-here-links-intro \"8. Debugging\")
diff --git a/eev-kla.el b/eev-kla.el
index d3e70df09d..dcd7c27ba1 100644
--- a/eev-kla.el
+++ b/eev-kla.el
@@ -19,7 +19,7 @@
 ;;
 ;; Author:     Eduardo Ochs <eduardoochs@gmail.com>
 ;; Maintainer: Eduardo Ochs <eduardoochs@gmail.com>
-;; Version:    20221115
+;; Version:    20221119
 ;; Keywords:   e-scripts
 ;;
 ;; Latest version: <http://angg.twu.net/eev-current/eev-kla.el>
@@ -28,21 +28,21 @@
 ;;                 <http://angg.twu.net/eev-intros/find-eev-intro.html>
 ;;                                                (find-eev-intro)
 
+;; «.tests»                    (to "tests")
 ;; «.intro»                    (to "intro")
 ;;  «.test»                    (to "test")
 ;;
 ;; «.variables»                        (to "variables")
-;; «.ee-kl-format1»            (to "ee-kl-format1")
-;; «.ee-kl-kill»               (to "ee-kl-kill")
-;; «.ee-kl-format2»            (to "ee-kl-format2")
-;; «.ee-kl-insert»             (to "ee-kl-insert")
 ;; «.ee-kl-expand»             (to "ee-kl-expand")
 ;; «.default-args»             (to "default-args")
 ;;
 ;; «.best-lrcd»                        (to "best-lrcd")
+;; «.ee-kl-r-c-d»              (to "ee-kl-r-c-d")
 ;; «.shorter-fnames»           (to "shorter-fnames")
 ;; «.generate-sexps»           (to "generate-sexps")
+;; «.ee-kl-kill»               (to "ee-kl-kill")
 ;; «.kill-sexps»               (to "kill-sexps")
+;; «.ee-kl-insert»             (to "ee-kl-insert")
 ;; «.eekla2»                   (to "eekla2")
 ;; «.aliases»                  (to "aliases")
 
@@ -51,6 +51,27 @@
 
 ;;; Commentary:
 
+;; «tests»  (to ".tests")
+;; Most of the docs about eev-kla.el are in this intro:
+;;
+;;   http://angg.twu.net/eev-intros/find-kla-intro.html
+;;                                 (find-kla-intro)
+;;
+;; Here are some tests that need to be run from a file. Try:
+;;
+;;   (ee-kl-anchor)
+;;   (ee-kl-c)
+;;   (ee-kl-sexp-kla)
+;;   (ee-kl-sexp-klf)
+;;   (ee-kl-sexp-klt)
+;;
+;; And then:
+;;
+;;   M-x eekla
+;;   M-x eeklf
+;;   M-x eeklt
+
+
 ;; WARNING (2022nov15): This is being rewritten!
 ;; One of my presentations at the EmacsConf2022 will be about
 ;; eev-kla.el. Its page is:
@@ -60,23 +81,6 @@
 ;; Right now - 2022nov15 - I am in the middle of rewriting both and
 ;; the code and the docs of eev-kla.el almost completely. The docs are
 ;; being moved to:
-;;
-;;   (find-kla-intro)
-;;
-;; And some concepts are changing. In my first versions of eev-kla.el
-;; the "preferred `c'" for a file was always obtained by reading the
-;; variable `ee-preferred-c', that was usually set using this:
-;;
-;;   (find-enode "Directory Variables")
-;;
-;; Then I added a way to guess the best `c' for a filename; then I
-;; made guessing the default way, and `ee-preferred-c' secondary; then
-;; I rewrote the algorithm for guessing, made it use this,
-;;
-;;   (find-kla-intro "4. The best `l-r-c-d'")
-;;   (find-kla-intro "5. `cl-loop'")
-;;
-;; and started to move all the docs to `(find-kla-intro)'.
 
 
 ;;
@@ -107,117 +111,6 @@
 ;;
 ;;
 ;;
-;; 2. The problem
-;; ==============
-;; This section of the main tutorial
-;;
-;;   (find-eev-quick-intro "10.1. Generating short hyperlinks to files")
-;;
-;; explains that after running these four `code-c-d's
-;;
-;;   (code-c-d "foo"  "/tmp/FOO/")
-;;   (code-c-d "bar"  "/tmp/FOO/BAR/")
-;;   (code-c-d "plic" "/tmp/FOO/BAR/PLIC/")
-;;
-;; all these sexp hyperlinks will point to the same file:
-;;
-;;   (find-file  "/tmp/FOO/BAR/PLIC/bletch")
-;;   (find-fline "/tmp/FOO/BAR/PLIC/bletch")
-;;   (find-foofile        "BAR/PLIC/bletch")
-;;   (find-barfile            "PLIC/bletch")
-;;   (find-plicfile                "bletch")
-;;
-;; So if we are in the file /tmp/FOO/BAR/PLIC/bletch then there isn't
-;; an obvious choice for the best short hyperlink to that file, and
-;; `find-here-links' will display all the choices above... Try this:
-;;
-;;   (eek "<down> M-3 M-e M-h M-h")
-;;   (find-fline "/tmp/FOO/BAR/PLIC/bletch")
-;;
-;; It will show the "here links" to /tmp/FOO/BAR/PLIC/bletch at the
-;; window at the right.
-;;
-;; The _standard_ way to create a link to /tmp/FOO/BAR/PLIC/bletch is
-;; to run `find-here-links' - i.e., `M-h M-h' - and then choose one of
-;; the hyperlinks, and do mark, copy, and paste. But sometimes we want
-;; something faster.
-;;
-;;
-;;
-;; 3. Converting `c's to `d's
-;; ==========================
-;; Remember that the arguments for a `code-c-d' are called "c" (for
-;; "code") and "d" (for "directory"),
-;;
-;;   (code-c-d "foo"  "/tmp/FOO/")
-;;   (code-c-d "bar"  "/tmp/FOO/BAR/")
-;;   (code-c-d "plic" "/tmp/FOO/BAR/PLIC/")
-;;   ;;         ^`c's  ^`d's
-;;
-;; We can run this to understand the code that the first `code-c-d'
-;; above runs,
-;;
-;;   (find-code-c-d "foo"  "/tmp/FOO/")
-;;
-;; and then we will see that there are two ways to convert the `c'
-;; "foo" to its corresponding `d', "/tmp/FOO/":
-;;
-;;   ee-foodir
-;;   ;; --> "/tmp/FOO/"
-;;   (ee-foofile "BAR/PLIC/bletch")
-;;   ;; --> "/tmp/FOO/BAR/PLIC/bletch"
-;;
-;;
-;;
-;; 4. Shortening filenames
-;; =======================
-;; Try:
-;;
-;;   (ee-kl-dir :c "foo")
-;;   (ee-kl-dir :c "bar")
-;;   (ee-kl-dir :c "plic")
-;;   (ee-kl-shortfname :c "foo"  :fname "/tmp/FOO/BAR/PLIC/bletch")
-;;   (ee-kl-shortfname :c "bar"  :fname "/tmp/FOO/BAR/PLIC/bletch")
-;;   (ee-kl-shortfname :c "plic" :fname "/tmp/FOO/BAR/PLIC/bletch")
-;;
-;; The functions `ee-kl-dir' and `ee-kl-shortfname' _sort of_ perform
-;; the opposite operations of `ee-{c}dir' and `ee-{c}file'. Try also
-;; this:
-;;
-;;   (ee-kl-sexp-klf :c "foo"  :fname "/tmp/FOO/BAR/PLIC/bletch")
-;;   (ee-kl-sexp-klf :c "bar"  :fname "/tmp/FOO/BAR/PLIC/bletch")
-;;   (ee-kl-sexp-klf :c "plic" :fname "/tmp/FOO/BAR/PLIC/bletch")
-;;
-;; The three sexps above return these other sexps:
-;;
-;;   (find-foofile "BAR/PLIC/bletch")
-;;   (find-barfile "PLIC/bletch")
-;;   (find-plicfile "bletch")
-;;
-;; that are three different short hyperlinks to the file
-;; /tmp/FOO/BAR/PLIC/bletch.
-;;
-;;
-;;
-;; 5. Defaults
-;; ===========
-;; When the functions `ee-kl-dir', `ee-kl-shortname', and
-;; `ee-kl-sexp-klf' above are called without keyword arguments they
-;; call certain functions to supply default values for those
-;; arguments. For example, this call
-;;
-;;   (ee-kl-sexp-klf)
-;;
-;; is equivalent to:
-;;
-;;   (ee-kl-sexp-klf :c (ee-kl-c) :fname (ee-kl-fname))
-;;
-;; The call to (ee-kl-fname) returns the file name of this file -
-;; nothing mysterious here - but the call to (ee-kl-c) returns the
-;; value of the variable `ee-preferred-c'.
-;;
-;;
-;;
 ;; 8. `eekla' and friends
 ;; ======================
 ;; At the moment this file implements these commands:
@@ -340,54 +233,6 @@
 ;;
 ;; The command `M-x kla2' (or `M-x eekla2') does that.
 ;;
-;; The _current implementation_ of `M-x kla2' - that will probably
-;; change soon! - is based on the following ideas:
-;;
-;;   1. Some people prefer to make commands like `M-x kla' kill a sexp
-;;      with a newline added at its end. These people can run this
-;;
-;;        (setq ee-kl-format1 "%s\n")
-;; 
-;;      to set that preference globally; other people will leave that
-;;      variable as `nil'.
-;;
-;;   2. The comment prefix can only be added later, because it depends
-;;      on the file in which the sexp will be inserted. The easiest
-;;      way to define which comment prefix to use is to set the
-;;      variable `ee-kl-format2' in the local variables section of
-;;      that file.
-;;
-;;   3. The command `M-x kli' - or `ee-kl-insert' - is like `C-y', but
-;;      it also adds the comment prefix.
-;;
-;;   4. The functions `ee-kl-format1' and `ee-kl-format2' - used,
-;;      respectively, by `ee-kl-kill' and `ee-kl-insert' - could be
-;;      defined like this,
-;;
-;;        (defun ee-kl-format1 (str)
-;;          (format (or ee-kl-format1 "%s") str))
-;;        (defun ee-kl-format2 (str)
-;;          (format (or ee-kl-format2 "%s") str))
-;;
-;;      but we want to add a hack to the function `ee-kl-format2'. Its
-;;      real definition is this one:
-;;
-;;        (defun ee-kl-format2 (str)
-;;          (format (or ee-kl-format2 (ee-kl-format2-for-mode) "%s") str))
-;;
-;;      So: when the variable `ee-kl-format2' is nil we run the
-;;      function `ee-kl-format2-for-mode' to try to get a default
-;;      value for the comment prefix based on the major mode. The
-;;      current definition of `ee-kl-format2-for-mode' is very
-;;      simplistic, but it is intended to be overriden by the user.
-;;
-;;   5. My first implementation of `M-x kla2' ran `M-x kla' twice and
-;;      `M-x kli' twice. The current implementation uses variants of
-;;      `kla' and `kli' that do not change the kill ring and that
-;;      always add the newlines - i.e., it ignores the value of the
-;;      variable `ee-kl-format1'.
-;;
-;;
 ;; 11. Overridable functions
 ;; =========================
 ;; On my machine I have some "living fossils" - the ones mentioned
@@ -432,85 +277,45 @@
 
 
 ;; «variables»  (to ".variables")
-;; See: (find-eev "eev-kla.el" "intro" "ee-preferred-c")
-;;      (find-eev "eev-kla.el" "intro" "ee-kl-format1")
-;;      (find-eev "eev-kla.el" "intro" "ee-kl-format2")
-;;      (find-eev "eev-tlinks.el" "ee-copy-rest" "eeflash-copy")
-;;
-(defvar ee-preferred-c nil
-  "See: (find-eev \"eev-kla.el\")")
-
-(defvar ee-preferred-c-guess t
-  "See: (find-eev \"eev-kla.el\")")
 
-(defvar ee-kl-format1 nil
-  "See: (find-eev \"eev-kla.el\")")
+(defvar ee-kl-transforms nil
+  "Set this if you need to support symlinks in eev-kla.el.
+The value of this variable should be list of (regexp replacement) pairs.")
 
-(defvar ee-kl-format2 nil
-  "See: (find-eev \"eev-kla.el\")")
-
-(defvar ee-kla2-flash-spec '(highlight 2.0))
 
-;;;###autoload
-(put 'ee-preferred-c 'safe-local-variable 'string-or-null-p)
-
-;;;###autoload
-(put 'ee-kl-format1 'safe-local-variable 'stringp)
-
-;;;###autoload
-(put 'ee-kl-insert2 'safe-local-variable 'stringp)
-
-;; «ee-kl-format1»  (to ".ee-kl-format1")
-;; «ee-kl-kill»  (to ".ee-kl-kill")
-;;
-(defun ee-kl-sexp-to-string (str-or-sexp)
-  (if (stringp str-or-sexp)
-      str-or-sexp
-    (ee-S str-or-sexp)))
-
-(defun ee-kl-format1 (str)
-  (format (or ee-kl-format1 "%s") str))
-
-(defun ee-kl-kill (str-or-sexp)
-  (let ((str (ee-kl-sexp-to-string str-or-sexp)))
-    (kill-new (ee-kl-format1 str))
-    (message "Copied to the kill ring: %s" str)))
-
-;; «ee-kl-format2»  (to ".ee-kl-format2")
-;; «ee-kl-insert»  (to ".ee-kl-insert")
-;; Test: (ee-kl-format2-for-mode)
-;;
-(defun ee-kl-format2-for-mode (&optional mode)
-  (let ((plist '(emacs-lisp-mode ";; %s"
-                haskell-mode    "-- %s"
-                lua-mode        "-- %s"
-                python-mode     "# %s"
-                agda2-mode      "-- %s"
-                latex-mode      "%% %s")))
-    (plist-get plist (or mode major-mode))))
-
-(defun ee-kl-format2 (str)
-  (format (or ee-kl-format2 (ee-kl-format2-for-mode) "%s") str))
-
-;; Used by `M-x kli'
-(defun ee-kl-insert (&optional str)
-  (interactive)
-  (let* ((str1 (or str (car kill-ring)))
-        (str2 (ee-kl-format2 str1)))
-    (insert str2)))
 
 
 
+;;;                  _    _                                       _ 
+;;;   ___  ___      | | _| |       _____  ___ __   __ _ _ __   __| |
+;;;  / _ \/ _ \_____| |/ / |_____ / _ \ \/ / '_ \ / _` | '_ \ / _` |
+;;; |  __/  __/_____|   <| |_____|  __/>  <| |_) | (_| | | | | (_| |
+;;;  \___|\___|     |_|\_\_|      \___/_/\_\ .__/ \__,_|_| |_|\__,_|
+;;;                                        |_|                      
 ;; «ee-kl-expand»  (to ".ee-kl-expand")
-;; Redefine this to support symlinks.
-;; TODO: write the docs.
+;; See: (find-kla-intro "9. Symlinks")
 ;;
 (defun ee-kl-expand (fname)
-  (ee-expand fname))
-
-
+  "Expand FNAME using `ee-expand'. Use other hacks if needed."
+  (ee-kl-transform (ee-expand fname)))
+
+(defun ee-kl-transform (fname)
+  "Transform FNAME into a canonical form.
+This is a hack to support symlinks in eev-kla.el. See the source."
+  (cl-loop for (regexp repl) in ee-kl-transforms
+           do (setq fname (replace-regexp-in-string regexp repl fname)))
+  fname)
+
+
+;;;  ____        __             _ _                         
+;;; |  _ \  ___ / _| __ _ _   _| | |_    __ _ _ __ __ _ ___ 
+;;; | | | |/ _ \ |_ / _` | | | | | __|  / _` | '__/ _` / __|
+;;; | |_| |  __/  _| (_| | |_| | | |_  | (_| | | | (_| \__ \
+;;; |____/ \___|_|  \__,_|\__,_|_|\__|  \__,_|_|  \__, |___/
+;;;                                               |___/     
 ;; «default-args»  (to ".default-args")
 ;; See: (find-kla-intro "6. `cl-defun'")
+;;      (find-kla-intro "7. The default `c', `d', and `r'")
 
 (defun ee-kl-fname ()
   (or (buffer-file-name) default-directory))
@@ -535,6 +340,10 @@
 ;; converted to an `l-r-c-d'. The ideas and the terminology are
 ;; explained here:
 ;;   (find-kla-intro "4. The best `l-r-c-d'")
+;;
+;; Tests: (find-eppp (ee-kl-cds))
+;;        (find-eppp (ee-kl-lrcds))
+;;                   (ee-kl-lrcd)
 
 (defun ee-kl-prefixp (prefix str)
   "If STR starts with PREFIX then return STR minus that prefix.
@@ -548,63 +357,63 @@ When STR doesn't start with PREFIX, return nil."
   (cl-loop for (c d) in ee-code-c-d-pairs
           collect (list c (ee-kl-expand d))))
 
-(cl-defun ee-kl-lrcds
-    (&key (fname (ee-kl-fname)))
+(cl-defun ee-kl-lrcds (&key fname)
   "Return all the `c-d's in (ee-kl-cds) that match FNAME.
 Each matching `c-d' is converted to an `l-r-c-d'."
+  (setq fname (or fname (ee-kl-fname)))
   (cl-loop for (c d) in (ee-kl-cds)
           if (ee-kl-prefixp d fname)
           collect (let* ((r (ee-kl-prefixp d fname))
                          (l (length r)))
                     (list l r c d))))
 
-(cl-defun ee-kl-lrcd
-    (&key (fname (ee-kl-fname)))
+(cl-defun ee-kl-lrcd (&key fname)
   "Return the best lrcd in (ee-kl-lrcds FNAME).
 If (ee-kl-lrcds FNAME) doesn't return any matching `lrcd's, return nil."
+  (setq fname (or fname (ee-kl-fname)))
   (let* ((lrcds (ee-kl-lrcds :fname fname))
         (l< (lambda (lrcd1 lrcd2) (< (car lrcd1) (car lrcd2))))
         (lrcds-sorted (sort lrcds l<)))
     (car lrcds-sorted)))
 
-(cl-defun ee-kl-c
-    (&key (fname (ee-kl-fname)))
-  (nth 2 (ee-kl-lrcd :fname fname)))
 
-(cl-defun ee-kl-r
-    (&key (fname (ee-kl-fname)))
+;;;  ____        __             _ _                         _ 
+;;; |  _ \  ___ / _| __ _ _   _| | |_   _ __    ___      __| |
+;;; | | | |/ _ \ |_ / _` | | | | | __| | '__|  / __|    / _` |
+;;; | |_| |  __/  _| (_| | |_| | | |_  | | _  | (__ _  | (_| |
+;;; |____/ \___|_|  \__,_|\__,_|_|\__| |_|( )  \___( )  \__,_|
+;;;                                       |/       |/         
+;; «ee-kl-r-c-d»  (to ".ee-kl-r-c-d")
+;; See: (find-kla-intro "7. The default `c', `d', and `r'")
+;; Tests: (ee-kl-r)
+;;        (ee-kl-c)
+;;        (ee-kl-d)
+
+(cl-defun ee-kl-r (&key fname)
+  (setq fname (or fname (ee-kl-fname)))
   (nth 1 (ee-kl-lrcd :fname fname)))
 
-;; (ee-kl-lrcds)
-;; (ee-kl-lrcd)
-;; (ee-kl-r)
-;; (ee-kl-c)
+(cl-defun ee-kl-c (&key fname)
+  (setq fname (or fname (ee-kl-fname)))
+  (nth 2 (ee-kl-lrcd :fname fname)))
+
+(cl-defun ee-kl-d (&key fname)
+  (setq fname (or fname (ee-kl-fname)))
+  (nth 3 (ee-kl-lrcd :fname fname)))
+
 
 ;; «shorter-fnames»  (to ".shorter-fnames")
 ;;
-(cl-defun ee-kl-shortfname
-    (&key (c (ee-kl-c))
-         (r (ee-kl-r)))
+(cl-defun ee-kl-shortfname (&key fname c r)
+  (setq fname (or fname (ee-kl-fname))
+       r     (or r     (ee-kl-r :fname fname)))
   r)
 
-(cl-defun ee-kl-shorterfname
-    (&key (c (ee-kl-c))
-         (r (ee-kl-r)))
+(cl-defun ee-kl-shorterfname (&key fname c r)
+  (setq fname (or fname (ee-kl-fname))
+       r     (or r     (ee-kl-r :fname fname)))
   r)
 
-(cl-defun ee-kl-find-c
-    (&key (c (ee-kl-c)))
-  (intern (format "find-%s" c)))
-
-(cl-defun ee-kl-find-cfile
-    (&key (c (ee-kl-c)))
-  (intern (format "find-%sfile" c)))
-
-
-
-
-
-
 
 
 ;;;  ____                      
@@ -620,44 +429,97 @@ If (ee-kl-lrcds FNAME) doesn't return any matching 
`lrcd's, return nil."
 ;;   (ee-kl-sexp-klas :region "foo")
 ;;   (ee-kl-sexp-klf)
 ;;   (ee-kl-sexp-klfs :region "foo")
+;;   (ee-kl-find-c)
+;;   (ee-kl-c)
 ;;
-(cl-defun ee-kl-sexp-kla
-    (&key (c      (ee-kl-c))
-     &key (r      (ee-kl-r))
-     &key (anchor (ee-kl-anchor)))
-  (list (ee-kl-find-c :c c)
-       (ee-kl-shorterfname :c c :r r)
+(cl-defun ee-kl-find-c (&key fname c)
+  "Generate a symbol of the form find-{c}."
+  (setq fname  (or fname  (ee-kl-fname))
+       c      (or c      (ee-kl-c :fname fname)))
+  (intern (format "find-%s" c)))
+
+(cl-defun ee-kl-find-cfile (&key fname c)
+  "Generate a symbol of the form find-{c}file."
+  (setq fname  (or fname  (ee-kl-fname))
+       c      (or c      (ee-kl-c)))
+  (intern (format "find-%sfile" c)))
+
+(cl-defun ee-kl-sexp-kla (&key fname c r anchor)
+  "<K>ill <l>ink to <a>nchor - make sexp."
+  (setq fname  (or fname  (ee-kl-fname))
+       c      (or c      (ee-kl-c))
+       r      (or r      (ee-kl-r))
+       anchor (or anchor (ee-kl-anchor)))
+  (list (ee-kl-find-c       :fname fname :c c)
+       (ee-kl-shorterfname :fname fname :c c :r r)
        anchor))
 
-(cl-defun ee-kl-sexp-klas
-    (&key (c      (ee-kl-c))
-     &key (r      (ee-kl-r))
-     &key (anchor (ee-kl-anchor))
-     &key (region (ee-kl-region)))
-  (list (ee-kl-find-c :c c)
-       (ee-kl-shorterfname :c c :r r)
+(cl-defun ee-kl-sexp-klas (&key fname c r anchor region)
+  "<K>ill <l>ink to <a>nchor and <s>tring - make sexp."
+  (setq fname  (or fname  (ee-kl-fname))
+       c      (or c      (ee-kl-c))
+       r      (or r      (ee-kl-r))
+       anchor (or anchor (ee-kl-anchor))
+       region (or region (ee-kl-region)))
+  (list (ee-kl-find-c       :fname fname :c c)
+       (ee-kl-shorterfname :fname fname :c c :r r)
        anchor
        region))
 
-(cl-defun ee-kl-sexp-klf
-    (&key (c (ee-kl-c))
-         (r (ee-kl-r)))
-  (list (ee-kl-find-cfile :c c)
-       (ee-kl-shortfname :c c :r r)))
-
-(cl-defun ee-kl-sexp-klfs
-    (&key (c      (ee-kl-c))
-         (r      (ee-kl-r))
-         (region (ee-kl-region)))
-  (list (ee-kl-find-cfile :c c)
-       (ee-kl-shortfname :c c :r r)
+(cl-defun ee-kl-sexp-klf (&key fname c r)
+  "<K>ill <l>ink to <f>ile - make sexp."
+  (setq fname (or fname (ee-kl-fname))
+       c     (or c     (ee-kl-c))
+       r     (or r     (ee-kl-r)))
+  (list (ee-kl-find-cfile :fname fname :c c)
+       (ee-kl-shortfname :fname fname :c c :r r)))
+
+(cl-defun ee-kl-sexp-klfs (&key fname c r region)
+  "<K>ill <l>ink to <f>ile and <s>tring - make sexp."
+  (setq fname  (or fname (ee-kl-fname))
+       c      (or c     (ee-kl-c :fname fname))
+       r      (or r     (ee-kl-r :fname fname))
+       region (or r     (ee-kl-region)))
+  (list (ee-kl-find-cfile :fname fname :c c)
+       (ee-kl-shortfname :fname fname :c c :r r)
        region))
 
-(cl-defun ee-kl-sexp-klt
-    (&key (anchor (ee-kl-anchor)))
+(cl-defun ee-kl-sexp-klt (&key anchor)
+  "<K>ill <l>ink to a (<t>o ...) - make sexp."
+  (setq anchor (or anchor (ee-kl-anchor)))
   (list 'to anchor))
 
 
+
+;;;                  _    _       _    _ _ _ 
+;;;   ___  ___      | | _| |     | | _(_) | |
+;;;  / _ \/ _ \_____| |/ / |_____| |/ / | | |
+;;; |  __/  __/_____|   <| |_____|   <| | | |
+;;;  \___|\___|     |_|\_\_|     |_|\_\_|_|_|
+;;;                                          
+;; «ee-kl-kill»  (to ".ee-kl-kill")
+;; Tests: (ee-kl-link-to-string "(foo)\n")
+;;        (ee-kl-link-to-string '(foo))
+
+(defun ee-kl-kill (link)
+  "Kill LINK and show a message.
+Here \"kill\" means \"put it in the kill ring.\""
+  (setq link (ee-kl-link-to-string link))
+  (let ((link0 (replace-regexp-in-string "\n$" "" link)))
+    (kill-new link)
+    (message "Copied to the kill ring: %s" link0)))
+
+(defun ee-kl-link-to-string (link)
+  "Convert LINK to a string using `ee-S'.
+If LINK is already a string, return it unchanged.
+If LINK is a sexp, convert it to a string with `ee-S' and append
+a newline to it."
+  (if (stringp link)
+      link
+    (concat (ee-S link) "\n")))
+
+
+
 ;;;  _  ___ _ _     
 ;;; | |/ (_) | |___ 
 ;;; | ' /| | | / __|
@@ -665,8 +527,7 @@ If (ee-kl-lrcds FNAME) doesn't return any matching `lrcd's, 
return nil."
 ;;; |_|\_\_|_|_|___/
 ;;;                 
 ;; «kill-sexps»  (to ".kill-sexps")
-;; Commands that push sexps into the kill ring. Note that
-;; they can be invoked with `M-x'.
+;; Commands that push sexps into the kill ring.
 ;;
 (defun eekla ()
   "<K>ill <L>ink to <A>nchor.
@@ -697,6 +558,37 @@ Put in the kill ring a link to the preceding anchor."
 
 
 
+;;;                  _    _       _                     _   
+;;;   ___  ___      | | _| |     (_)_ __  ___  ___ _ __| |_ 
+;;;  / _ \/ _ \_____| |/ / |_____| | '_ \/ __|/ _ \ '__| __|
+;;; |  __/  __/_____|   <| |_____| | | | \__ \  __/ |  | |_ 
+;;;  \___|\___|     |_|\_\_|     |_|_| |_|___/\___|_|   \__|
+;;;                                                         
+;; «ee-kl-insert»  (to ".ee-kl-insert")
+;; Tests: (ee-kl-comment-prefix)
+;;        (ee-kl-insert "(foo)\n")
+;;
+(defun ee-kl-comment-prefix (&optional mode)
+  "This a quick hack. Override it to add support for more languages."
+  (let ((plist '(emacs-lisp-mode ";; "
+                haskell-mode    "-- "
+                lua-mode        "-- "
+                python-mode     "# "
+                agda2-mode      "-- "
+                latex-mode      "%% ")))
+    (plist-get plist (or mode major-mode))))
+
+(defun ee-kl-link-to-string-with-comment (link)
+  (concat (or (ee-kl-comment-prefix) "# ")
+         (ee-kl-link-to-string link)))
+
+(defun ee-kl-insert (&optional link)
+  "Insert (ee-kl-comment-prefix) and then LINK."
+  (interactive)
+  (insert (ee-kl-link-to-string-with-comment (car kill-ring))))
+
+
+
 
 ;;;            _    _       ____  
 ;;;   ___  ___| | _| | __ _|___ \ 
@@ -706,32 +598,42 @@ Put in the kill ring a link to the preceding anchor."
 ;;;                               
 ;; «eekla2»  (to ".eekla2")
 ;; See: (find-eev "eev-kla.el" "intro" "10. Bidirectional links")
+
+;; Based on:
+;;   (find-eev "eev-flash.el" "specs")
+;;   (find-eev "eev-tlinks.el" "ee-copy-rest" "eeflash-copy")
+;; but lasts longer.
 ;;
-(defun ee-kla2-bol ()
-  (when (not (= (ee-bol) (point)))     ; when not at bol
-    (move-beginning-of-line 2))                ; do <down> C-a
-  (point))
+(defvar ee-kla2-flash-spec '(highlight 2.0))
 
 (defun ee-kla2-flash (pos1 pos2)
+  "Highlight the region between POS1 and POS2 using `ee-kla2-flash-spec'."
   (eeflash pos1 (point) ee-kla2-flash-spec))
 
-(defun ee-kla2-insert (sexp)
-  (let* ((str1 (format "%s\n" (ee-S sexp)))
-        (str2 (ee-kl-format2 str1))
-        (pos1 (ee-kla2-bol)))
-    (insert str2)
-    (ee-kla2-flash pos1 (point))))
+(defun ee-kla2-goto-bol ()
+  "Move to the beginning of the line.
+When not at BOL, move to the beginning of the next line."
+  (when (not (= (ee-bol) (point)))     ; when not at bol
+    (move-beginning-of-line 2))                ; do <down> C-a
+  (point))
+
+(defun ee-kla2-insert (link)
+  "Move to the beginning of the line, insert LINK, and highlight it."
+  (let* ((line (ee-kl-link-to-string-with-comment link))
+        (pos-before-line (ee-kla2-goto-bol)))
+    (insert line)
+    (ee-kla2-flash pos-before-line (point))))
 
 (defun eekla2 ()
   "Insert a link \"to here\" \"there\" and a link \"to there\" \"here\"."
   (interactive)
-  (let* ((sexp1 (ee-kl-sexp-kla))
-        (sexp2 (prog2 (other-window 1)
+  (let* ((link1 (ee-kl-sexp-kla))
+        (link2 (prog2 (other-window 1)
                    (ee-kl-sexp-kla)
                  (other-window -1))))
-    (ee-kla2-insert sexp2)
+    (ee-kla2-insert link2)
     (other-window 1)
-    (ee-kla2-insert sexp1)
+    (ee-kla2-insert link1)
     (other-window -1)))
 
 
@@ -743,6 +645,7 @@ Put in the kill ring a link to the preceding anchor."
 ;;; /_/   \_\_|_|\__,_|___/\___||___/
 ;;;                                  
 ;; «aliases»  (to ".aliases")
+;; See: (find-kla-intro "10. Aliases")
 ;; I use these aliases:
 ;; (defalias 'kla  'eekla)
 ;; (defalias 'klas 'eeklas)



reply via email to

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