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

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

[nongnu] elpa/cycle-at-point 319d30df35 08/18: Cleanup: emacs native for


From: ELPA Syncer
Subject: [nongnu] elpa/cycle-at-point 319d30df35 08/18: Cleanup: emacs native format
Date: Sun, 21 Apr 2024 21:59:37 -0400 (EDT)

branch: elpa/cycle-at-point
commit 319d30df35acee2de68a421d14dc5b301bb874a5
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Cleanup: emacs native format
---
 cycle-at-point-find-alphabet.el          |  14 +-
 cycle-at-point-find-integer.el           | 163 +++++++--------
 cycle-at-point-preset-c++-mode.el        |   8 +-
 cycle-at-point-preset-c-mode.el          |  34 +--
 cycle-at-point-preset-cmake-mode.el      |  12 +-
 cycle-at-point-preset-emacs-lisp-mode.el |  20 +-
 cycle-at-point-preset-lang-en.el         |  42 ++--
 cycle-at-point-preset-python-mode.el     |  32 +--
 cycle-at-point.el                        | 341 +++++++++++++++----------------
 tests/cycle-at-point-tests.el            |  17 +-
 10 files changed, 328 insertions(+), 355 deletions(-)

diff --git a/cycle-at-point-find-alphabet.el b/cycle-at-point-find-alphabet.el
index 6d990da484..8ec029cee5 100644
--- a/cycle-at-point-find-alphabet.el
+++ b/cycle-at-point-find-alphabet.el
@@ -13,20 +13,18 @@
 
 (defun cycle-at-point-find-alphabet-ascii ()
   "Return alphabetical characters matching the symbol at-point."
-  (let
-    (
-      (result (list))
-      (word (bounds-of-thing-at-point 'symbol))
-      (word-upcase nil))
+  (let ((result (list))
+        (word (bounds-of-thing-at-point 'symbol))
+        (word-upcase nil))
     (when word
       (setq word (buffer-substring-no-properties (car word) (cdr word)))
       (when (eq 1 (length word))
         (setq word-upcase (upcase word))
         (when (string-match-p "[A-Z]" word-upcase)
           (setq result
-            (list
-              "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" ;; Alphabet 
literal.
-              "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
+                (list
+                 "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" ;; 
Alphabet literal.
+                 "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"))
           (unless (string-equal word word-upcase)
             (setq result (mapcar (lambda (w) (downcase w)) result))))))
     (list :data result)))
diff --git a/cycle-at-point-find-integer.el b/cycle-at-point-find-integer.el
index 08e78c9f5c..ced82c77a2 100644
--- a/cycle-at-point-find-integer.el
+++ b/cycle-at-point-find-integer.el
@@ -16,35 +16,33 @@
   "Format NUMBER as binary.
 Fill up to WIDTH with FILLCHAR (defaults to ?0) if binary
 representation of NUMBER is smaller."
-  (let
-    (
-      (nums (list))
-      (fillchar (or fillchar ?0)))
+  (let ((nums (list))
+        (fillchar (or fillchar ?0)))
     (while (> number 0)
       (push (number-to-string (% number 2)) nums)
       (setq number (truncate number 2)))
     (let ((len (length nums)))
       (apply #'concat
-        (cond
-          ((and width (< len width))
-            (make-string (- width len) fillchar))
-          (t
-            ""))
-        nums))))
+             (cond
+              ((and width (< len width))
+               (make-string (- width len) fillchar))
+              (t
+               ""))
+             nums))))
 
 (defun cycle-at-point-find-integer--format (num width base)
   "Format NUM with at least WIDTH space in BASE."
   (cond
-    ((eq base 2)
-      (cycle-at-point-find-integer--format-binary num width))
-    ((eq base 8)
-      (format (format "%%0%do" width) num))
-    ((eq base 16)
-      (format (format "%%0%dX" width) num))
-    ((eq base 10)
-      (format (format "%%0%dd" width) num))
-    (t
-      (error "Invalid base"))))
+   ((eq base 2)
+    (cycle-at-point-find-integer--format-binary num width))
+   ((eq base 8)
+    (format (format "%%0%do" width) num))
+   ((eq base 16)
+    (format (format "%%0%dX" width) num))
+   ((eq base 10)
+    (format (format "%%0%dd" width) num))
+   (t
+    (error "Invalid base"))))
 
 
 ;; ---------------------------------------------------------------------------
@@ -57,52 +55,46 @@ Optional keyword ARGS:
   A list of bases which this mode supports.
 `:undescore-sep'
   When true, ignore underscores."
-  (let
-    (
-      (supported-bases (plist-get args :bases))
-      (underscore-sep (plist-get args :underscore-sep))
-      (any-chars "")
-      (any-prefix "")
-      (pt-init (point))
-      (pt-beg (line-beginning-position))
-      (result nil))
+  (let ((supported-bases (plist-get args :bases))
+        (underscore-sep (plist-get args :underscore-sep))
+        (any-chars "")
+        (any-prefix "")
+        (pt-init (point))
+        (pt-beg (line-beginning-position))
+        (result nil))
 
     (dolist (base supported-bases)
       (cond
-        ((eq base 2)
-          (setq any-prefix (concat any-prefix "bB"))
-          (setq any-chars (concat any-chars "0-1")))
-        ((eq base 8)
-          (setq any-prefix (concat any-prefix "oO"))
-          (setq any-chars (concat any-chars "0-7")))
-        ((eq base 10)
-          (setq any-chars (concat any-chars "0-9")))
-        ((eq base 16)
-          (setq any-prefix (concat any-prefix "xX"))
-          (setq any-chars (concat any-chars "0-9a-fA-F")))))
+       ((eq base 2)
+        (setq any-prefix (concat any-prefix "bB"))
+        (setq any-chars (concat any-chars "0-1")))
+       ((eq base 8)
+        (setq any-prefix (concat any-prefix "oO"))
+        (setq any-chars (concat any-chars "0-7")))
+       ((eq base 10)
+        (setq any-chars (concat any-chars "0-9")))
+       ((eq base 16)
+        (setq any-prefix (concat any-prefix "xX"))
+        (setq any-chars (concat any-chars "0-9a-fA-F")))))
 
     (save-excursion
       ;; Important not to skip over non-numbers.
       (goto-char (min (1+ (point)) (line-end-position)))
-      (when
-        (zerop
-          (skip-chars-backward
-            (concat
-              any-chars any-prefix
-              (cond
-                (underscore-sep
-                  "_")
-                (t
-                  "")))
-            pt-beg))
+      (when (zerop
+             (skip-chars-backward (concat
+                                   any-chars any-prefix
+                                   (cond
+                                    (underscore-sep
+                                     "_")
+                                    (t
+                                     "")))
+                                  pt-beg))
         (goto-char pt-init))
-      (let
-        (
-          (base 10)
-          (pt-start (point))
-          (c nil)
-          (c-is-upper nil)
-          (c-search nil))
+      (let ((base 10)
+            (pt-start (point))
+            (c nil)
+            (c-is-upper nil)
+            (c-search nil))
 
         (when (looking-at (concat "0[" any-prefix "]"))
           (setq c (char-after (1+ (point))))
@@ -113,20 +105,20 @@ Optional keyword ARGS:
           (forward-char 2))
 
         (cond
-          ((eq c ?b)
-            (setq base 2)
-            (setq c-search "[0-1_]+"))
-          ((eq c ?o)
-            (setq base 8)
-            (setq c-search "[0-7_]+"))
-          ((null c)
-            (setq base 10)
-            (setq c-search "[0-9_]+"))
-          ((eq c ?x)
-            (setq base 16)
-            (setq c-search "[0-9_a-fA-F]+"))
-          (t
-            (error "Internal error")))
+         ((eq c ?b)
+          (setq base 2)
+          (setq c-search "[0-1_]+"))
+         ((eq c ?o)
+          (setq base 8)
+          (setq c-search "[0-7_]+"))
+         ((null c)
+          (setq base 10)
+          (setq c-search "[0-9_]+"))
+         ((eq c ?x)
+          (setq base 16)
+          (setq c-search "[0-9_a-fA-F]+"))
+         (t
+          (error "Internal error")))
 
         (when (looking-at c-search)
           (let ((text (buffer-substring-no-properties pt-start (match-end 0))))
@@ -137,23 +129,20 @@ Optional keyword ARGS:
 
               (let ((num (string-to-number text-eval base)))
                 (dolist (base-data (list (cons 16 "0x") (cons 10 "") (cons 8 
"0o") (cons 2 "0b")))
-                  (let
-                    (
-                      (base-iter (car base-data))
-                      (base-prefix (cdr base-data)))
+                  (let ((base-iter (car base-data))
+                        (base-prefix (cdr base-data)))
                     ;; If this base is supported.
                     (when (member base-iter supported-bases)
-                      (push
-                        (cond
-                          ((eq base base-iter)
-                            text)
-                          (t
-                            (when c-is-upper
-                              (setq base-prefix (upcase base-prefix)))
-                            (concat
-                              base-prefix
-                              (cycle-at-point-find-integer--format num 1 
base-iter))))
-                        result))))))))))
+                      (push (cond
+                             ((eq base base-iter)
+                              text)
+                             (t
+                              (when c-is-upper
+                                (setq base-prefix (upcase base-prefix)))
+                              (concat
+                               base-prefix
+                               (cycle-at-point-find-integer--format num 1 
base-iter))))
+                            result))))))))))
     (list :data result)))
 
 (provide 'cycle-at-point-find-integer)
diff --git a/cycle-at-point-preset-c++-mode.el 
b/cycle-at-point-preset-c++-mode.el
index ea85ed75f1..f6bc6fbb12 100644
--- a/cycle-at-point-preset-c++-mode.el
+++ b/cycle-at-point-preset-c++-mode.el
@@ -13,10 +13,10 @@
 (defun cycle-at-point-preset-c++-mode ()
   "Return a preset list compatible with `cycle-at-point-list'."
   (append
-    (cycle-at-point-preset-c-mode)
-    (list
-      ;; Mostly shared with C.
-      (list :data (list "public" "private")))))
+   (cycle-at-point-preset-c-mode)
+   (list
+    ;; Mostly shared with C.
+    (list :data (list "public" "private")))))
 
 (provide 'cycle-at-point-preset-c++-mode)
 ;;; cycle-at-point-preset-c++-mode.el ends here
diff --git a/cycle-at-point-preset-c-mode.el b/cycle-at-point-preset-c-mode.el
index 6ac13e4463..fbd228130a 100644
--- a/cycle-at-point-preset-c-mode.el
+++ b/cycle-at-point-preset-c-mode.el
@@ -15,23 +15,23 @@
 (defun cycle-at-point-preset-c-mode ()
   "Return a preset list compatible with `cycle-at-point-list'."
   (list
-    (list :data (list "true" "false"))
-    (list :data (list "&" "|"))
-    (list :data (list "&=" "|="))
-    (list :data (list "&&" "||"))
-    (list :data (list "<" ">"))
-    (list :data (list "<=" ">="))
-    (list :data (list "<<" ">>"))
-    (list :data (list "<<=" ">>="))
-    (list :data (list "!=" "=="))
-    (list :data (list "/" "*"))
-    (list :data (list "/=" "*="))
-    (list :data (list "+" "-"))
-    (list :data (list "+=" "-="))
-    (list :data (list "++" "--"))
-    (list :data (list "unsigned" "signed"))
-    (lambda () (cycle-at-point-find-alphabet-ascii))
-    (lambda () (cycle-at-point-find-integer-bases :bases (list 10 16)))))
+   (list :data (list "true" "false"))
+   (list :data (list "&" "|"))
+   (list :data (list "&=" "|="))
+   (list :data (list "&&" "||"))
+   (list :data (list "<" ">"))
+   (list :data (list "<=" ">="))
+   (list :data (list "<<" ">>"))
+   (list :data (list "<<=" ">>="))
+   (list :data (list "!=" "=="))
+   (list :data (list "/" "*"))
+   (list :data (list "/=" "*="))
+   (list :data (list "+" "-"))
+   (list :data (list "+=" "-="))
+   (list :data (list "++" "--"))
+   (list :data (list "unsigned" "signed"))
+   (lambda () (cycle-at-point-find-alphabet-ascii))
+   (lambda () (cycle-at-point-find-integer-bases :bases (list 10 16)))))
 
 (provide 'cycle-at-point-preset-c-mode)
 ;;; cycle-at-point-preset-c-mode.el ends here
diff --git a/cycle-at-point-preset-cmake-mode.el 
b/cycle-at-point-preset-cmake-mode.el
index b59a18a287..cb3a6beaa2 100644
--- a/cycle-at-point-preset-cmake-mode.el
+++ b/cycle-at-point-preset-cmake-mode.el
@@ -15,12 +15,12 @@
   "Return a preset list compatible with `cycle-at-point-list'."
   ;; Note that CMAKE is case insensitive.
   (list
-    (list :data (list "TRUE" "FALSE") :case-fold t)
-    (list :data (list "ON" "OFF") :case-fold t)
-    (list :data (list "AND" "OR") :case-fold t)
-    (list :data (list "VERSION_LESS" "VERSION_GREATER") :case-fold t)
-    (list :data (list "VERSION_LESS_EQUAL" "VERSION_GREATER_EQUAL") :case-fold 
t)
-    (lambda () (cycle-at-point-find-alphabet-ascii))))
+   (list :data (list "TRUE" "FALSE") :case-fold t)
+   (list :data (list "ON" "OFF") :case-fold t)
+   (list :data (list "AND" "OR") :case-fold t)
+   (list :data (list "VERSION_LESS" "VERSION_GREATER") :case-fold t)
+   (list :data (list "VERSION_LESS_EQUAL" "VERSION_GREATER_EQUAL") :case-fold 
t)
+   (lambda () (cycle-at-point-find-alphabet-ascii))))
 
 (provide 'cycle-at-point-preset-cmake-mode)
 ;;; cycle-at-point-preset-cmake-mode.el ends here
diff --git a/cycle-at-point-preset-emacs-lisp-mode.el 
b/cycle-at-point-preset-emacs-lisp-mode.el
index 08edf14a05..3ecd0c2ddc 100644
--- a/cycle-at-point-preset-emacs-lisp-mode.el
+++ b/cycle-at-point-preset-emacs-lisp-mode.el
@@ -14,16 +14,16 @@
 (defun cycle-at-point-preset-emacs-lisp-mode ()
   "Return a preset list compatible with `cycle-at-point-list'."
   (list
-    (list :data (list "t" "nil"))
-    (list :data (list "and" "or"))
-    (list :data (list "when" "unless"))
-    (list :data (list "<" ">"))
-    (list :data (list "/" "*"))
-    (list :data (list "+" "-"))
-    (list :data (list ">=" "<="))
-    (list :data (list "car" "cdr"))
-    (list :data (list "string-lessp" "string-greaterp"))
-    (lambda () (cycle-at-point-find-alphabet-ascii))))
+   (list :data (list "t" "nil"))
+   (list :data (list "and" "or"))
+   (list :data (list "when" "unless"))
+   (list :data (list "<" ">"))
+   (list :data (list "/" "*"))
+   (list :data (list "+" "-"))
+   (list :data (list ">=" "<="))
+   (list :data (list "car" "cdr"))
+   (list :data (list "string-lessp" "string-greaterp"))
+   (lambda () (cycle-at-point-find-alphabet-ascii))))
 
 (provide 'cycle-at-point-preset-emacs-lisp-mode)
 ;;; cycle-at-point-preset-emacs-lisp-mode.el ends here
diff --git a/cycle-at-point-preset-lang-en.el b/cycle-at-point-preset-lang-en.el
index e02d0e7f42..dec91c5647 100644
--- a/cycle-at-point-preset-lang-en.el
+++ b/cycle-at-point-preset-lang-en.el
@@ -12,28 +12,28 @@
 (defun cycle-at-point-preset-lang-en ()
   "Return a preset list compatible with `cycle-at-point-list'."
   (list
-    ;; Days of the week.
+   ;; Days of the week.
+   (list
+    :data (list "MONDAY" "TUESDAY" "WEDNESDAY" "THURSDAY" "FRIDAY" "SATURDAY" 
"SUNDAY")
+    :case-fold t)
+   (list :data (list "MON" "TUE" "WED" "THU" "FRI" "SAT" "SUN") :case-fold t)
+   ;; Months of the year.
+   (list
+    :data
     (list
-      :data (list "MONDAY" "TUESDAY" "WEDNESDAY" "THURSDAY" "FRIDAY" 
"SATURDAY" "SUNDAY")
-      :case-fold t)
-    (list :data (list "MON" "TUE" "WED" "THU" "FRI" "SAT" "SUN") :case-fold t)
-    ;; Months of the year.
-    (list
-      :data
-      (list
-        "JANUARY"
-        "FEBRUARY"
-        "MARCH"
-        "APRIL"
-        "MAY"
-        "JUNE"
-        "JULY"
-        "AUGUST"
-        "SEPTEMBER"
-        "OCTOBER"
-        "NOVEMBER"
-        "DECEMBER")
-      :case-fold t)))
+     "JANUARY"
+     "FEBRUARY"
+     "MARCH"
+     "APRIL"
+     "MAY"
+     "JUNE"
+     "JULY"
+     "AUGUST"
+     "SEPTEMBER"
+     "OCTOBER"
+     "NOVEMBER"
+     "DECEMBER")
+    :case-fold t)))
 
 (provide 'cycle-at-point-preset-lang-en)
 ;;; cycle-at-point-preset-lang-en.el ends here
diff --git a/cycle-at-point-preset-python-mode.el 
b/cycle-at-point-preset-python-mode.el
index e6d4f0dbd5..86f5a41d84 100644
--- a/cycle-at-point-preset-python-mode.el
+++ b/cycle-at-point-preset-python-mode.el
@@ -15,22 +15,22 @@
 (defun cycle-at-point-preset-python-mode ()
   "Return a preset list compatible with `cycle-at-point-list'."
   (list
-    (list :data (list "True" "False"))
-    (list :data (list "&" "|"))
-    (list :data (list "&=" "|="))
-    (list :data (list "and" "or"))
-    (list :data (list "is not" "is"))
-    (list :data (list "<" ">"))
-    (list :data (list "<=" ">="))
-    (list :data (list "<<" ">>"))
-    (list :data (list "<<=" ">>="))
-    (list :data (list "!=" "=="))
-    (list :data (list "/" "*"))
-    (list :data (list "/=" "*="))
-    (list :data (list "+" "-"))
-    (list :data (list "+=" "-="))
-    (lambda () (cycle-at-point-find-integer-bases :bases (list 2 8 10 16) 
:underscore-sep t))
-    (lambda () (cycle-at-point-find-alphabet-ascii))))
+   (list :data (list "True" "False"))
+   (list :data (list "&" "|"))
+   (list :data (list "&=" "|="))
+   (list :data (list "and" "or"))
+   (list :data (list "is not" "is"))
+   (list :data (list "<" ">"))
+   (list :data (list "<=" ">="))
+   (list :data (list "<<" ">>"))
+   (list :data (list "<<=" ">>="))
+   (list :data (list "!=" "=="))
+   (list :data (list "/" "*"))
+   (list :data (list "/=" "*="))
+   (list :data (list "+" "-"))
+   (list :data (list "+=" "-="))
+   (lambda () (cycle-at-point-find-integer-bases :bases (list 2 8 10 16) 
:underscore-sep t))
+   (lambda () (cycle-at-point-find-alphabet-ascii))))
 
 (provide 'cycle-at-point-preset-python-mode)
 ;;; cycle-at-point-preset-python-mode.el ends here
diff --git a/cycle-at-point.el b/cycle-at-point.el
index 814f2b4623..b93c60bf87 100644
--- a/cycle-at-point.el
+++ b/cycle-at-point.el
@@ -63,183 +63,171 @@ Each list item can contain keyword/value pairs:
 (defun cycle-at-point--cycle-words (cycle-data)
   "Return the bounds of the thing at point from CYCLE-DATA."
   (let
-    ( ;; Only for error messages.
-      (cycle-data-index 0)
-      (prefix "cycle-at-point")
-      (pt (point))
-      (line-beg (line-beginning-position))
-      (line-end (line-end-position))
+      ( ;; Only for error messages.
+       (cycle-data-index 0)
+       (prefix "cycle-at-point")
+       (pt (point))
+       (line-beg (line-beginning-position))
+       (line-end (line-end-position))
 
-      (result nil))
+       (result nil))
 
     (while (and (null result) cycle-data)
       (let
-        ( ;; Extract keyword arguments from `arg-data'.
-          (arg-data (pop cycle-data))
+          ( ;; Extract keyword arguments from `arg-data'.
+           (arg-data (pop cycle-data))
 
-          (arg-case-fold nil)
-          (arg-words nil))
+           (arg-case-fold nil)
+           (arg-words nil))
 
         ;; May be callable.
         (when (functionp arg-data)
           (condition-case-unless-debug err
-            (save-match-data
-              (save-excursion
-                (unless (eq (point) pt)
-                  (error "Internal error, unexpected point motion"))
-                (setq arg-data (funcall arg-data))))
+              (save-match-data
+                (save-excursion
+                  (unless (eq (point) pt)
+                    (error "Internal error, unexpected point motion"))
+                  (setq arg-data (funcall arg-data))))
             (error
-              (user-error
-                "%s: (error at index %d) unable to use callback (%S)"
-                prefix
-                cycle-data-index
-                err))))
+             (user-error "%s: (error at index %d) unable to use callback (%S)"
+                         prefix
+                         cycle-data-index
+                         err))))
 
         ;; Parse arguments.
         (while arg-data
           (let ((arg-current (pop arg-data)))
             (cond
-              ((keywordp arg-current)
-                (unless arg-data
-                  (user-error
-                    "%s: (error at index %d) keyword argument %S has no value!"
-                    prefix
-                    cycle-data-index
-                    arg-current))
-                (let ((v (pop arg-data)))
-                  (pcase arg-current
-                    (:data
-                      (cond
-                        ;; Callback to generate data.
-                        ((functionp v)
-                          (condition-case-unless-debug err
-                            (save-match-data
-                              (save-excursion
-                                (unless (eq (point) pt)
-                                  (error "Internal error, unexpected point 
motion"))
-                                (setq v (funcall v))
-                                (unless (listp v)
-                                  (error
-                                    "Expected a list of strings, not %S = %S" 
(type-of v) v))))
-                            (error
-                              (user-error
-                                "%s: (error at index %d), :data callback 
failure %S"
-                                prefix
-                                cycle-data-index
-                                err))))
-                        ((listp v))
-                        (t
-                          (error
-                            "%s: expected `:data', to be a list of strings, 
found %S"
+             ((keywordp arg-current)
+              (unless arg-data
+                (user-error "%s: (error at index %d) keyword argument %S has 
no value!"
                             prefix
-                            (type-of v))))
-                      (setq arg-words v))
-                    (:case-fold
-                      (cond
-                        ((memq v (list nil t)))
-                        (t
-                          (error "%s: expected `:case-fold', to be nil or t" 
prefix)))
-                      (setq arg-case-fold v))
-                    (_ (error "Unknown argument %S" arg-current)))))
-              (t
-                (user-error
-                  "%s: (error at index %d) all arguments must be keyword, 
value pairs, found %S"
-                  prefix
-                  cycle-data-index
-                  (type-of arg-current))))))
+                            cycle-data-index
+                            arg-current))
+              (let ((v (pop arg-data)))
+                (pcase arg-current
+                  (:data
+                   (cond
+                    ;; Callback to generate data.
+                    ((functionp v)
+                     (condition-case-unless-debug err
+                         (save-match-data
+                           (save-excursion
+                             (unless (eq (point) pt)
+                               (error "Internal error, unexpected point 
motion"))
+                             (setq v (funcall v))
+                             (unless (listp v)
+                               (error "Expected a list of strings, not %S = 
%S" (type-of v) v))))
+                       (error
+                        (user-error "%s: (error at index %d), :data callback 
failure %S"
+                                    prefix
+                                    cycle-data-index
+                                    err))))
+                    ((listp v))
+                    (t
+                     (error
+                      "%s: expected `:data', to be a list of strings, found %S"
+                      prefix
+                      (type-of v))))
+                   (setq arg-words v))
+                  (:case-fold
+                   (cond
+                    ((memq v (list nil t)))
+                    (t
+                     (error "%s: expected `:case-fold', to be nil or t" 
prefix)))
+                   (setq arg-case-fold v))
+                  (_ (error "Unknown argument %S" arg-current)))))
+             (t
+              (user-error
+               "%s: (error at index %d) all arguments must be keyword, value 
pairs, found %S"
+               prefix
+               cycle-data-index
+               (type-of arg-current))))))
         ;; Done parsing arguments.
 
-        (let*
-          (
-            (case-fold-search arg-case-fold)
-            (words-max 0)
-            (words-length 0)
-            (words-regex
-              (concat
-                (mapconcat
-                  #'
-                  (lambda (literal)
-                    (setq words-max (max words-max (length literal)))
-                    (setq words-length (1+ words-length))
-                    ;; Use groups so they can be checked.
-                    (concat "\\(" (regexp-quote literal) "\\)"))
-                  arg-words "\\|")))
-
-            ;; Anything outside this range wont overlap `pt'.
-            (search-min (max (- pt words-max) line-beg))
-            (search-max (min (+ pt words-max) line-end)))
+        (let* ((case-fold-search arg-case-fold)
+               (words-max 0)
+               (words-length 0)
+               (words-regex
+                (concat
+                 (mapconcat #'(lambda (literal)
+                                (setq words-max (max words-max (length 
literal)))
+                                (setq words-length (1+ words-length))
+                                ;; Use groups so they can be checked.
+                                (concat "\\(" (regexp-quote literal) "\\)"))
+                            arg-words
+                            "\\|")))
+
+               ;; Anything outside this range wont overlap `pt'.
+               (search-min (max (- pt words-max) line-beg))
+               (search-max (min (+ pt words-max) line-end)))
 
           (save-match-data
             (save-excursion
               (goto-char search-min)
               (while (and (< (point) search-max) (re-search-forward 
words-regex search-max t))
-                (let
-                  (
-                    (beg (match-beginning 0))
-                    (end (match-end 0)))
+                (let ((beg (match-beginning 0))
+                      (end (match-end 0)))
 
                   ;; Even if the point has been found,
                   ;; it's possible the word found was shorter, meaning the 
point is not over it.
                   (cond
-                    ;; Keep searching.
-                    ((< end pt)
-                      (goto-char (1+ beg)))
-                    ;; Stop searching (past the point).
-                    ((< pt beg)
-                      (goto-char search-max))
-
-                    ;; Overlapping match, now check delimiters (via syntax 
table).
-
-                    ;; Delimit on unchanged syntax-class at the beginning.
-                    ((and (< line-beg beg) (eq (syntax-after beg) 
(syntax-after (1- beg))))
-                      ;; This match doesn't end at delimiters, keep searching.
-                      (goto-char (1+ beg)))
-
-                    ;; Delimit on unchanged syntax-class at the end.
-                    ((and (< end line-end) (eq (syntax-after end) 
(syntax-after (1- end))))
-                      ;; This match doesn't end at delimiters, keep searching.
-                      (goto-char (1+ beg)))
-
-                    ;; Cycle word list!
-                    (t
-                      (let
-                        (
-                          (i 0)
+                   ;; Keep searching.
+                   ((< end pt)
+                    (goto-char (1+ beg)))
+                   ;; Stop searching (past the point).
+                   ((< pt beg)
+                    (goto-char search-max))
+
+                   ;; Overlapping match, now check delimiters (via syntax 
table).
+
+                   ;; Delimit on unchanged syntax-class at the beginning.
+                   ((and (< line-beg beg) (eq (syntax-after beg) (syntax-after 
(1- beg))))
+                    ;; This match doesn't end at delimiters, keep searching.
+                    (goto-char (1+ beg)))
+
+                   ;; Delimit on unchanged syntax-class at the end.
+                   ((and (< end line-end) (eq (syntax-after end) (syntax-after 
(1- end))))
+                    ;; This match doesn't end at delimiters, keep searching.
+                    (goto-char (1+ beg)))
+
+                   ;; Cycle word list!
+                   (t
+                    (let ((i 0)
                           (not-found t))
-                        (while (and not-found (< i words-length))
-                          (cond
-                            ((match-string-no-properties (1+ i))
-                              (setq i (1- i))
-                              (setq not-found nil))
-                            (t
-                              (setq i (1+ i)))))
-
-                        ;; Move the current word last.
-                        (setq i (mod (1+ i) words-length))
-                        (let ((word-orig (buffer-substring-no-properties beg 
end)))
-                          ;; Match the case of the existing word (when case is 
folded).
-                          (when arg-case-fold
-                            (setq arg-words
-                              (cond
-                                ((string-equal (upcase word-orig) word-orig)
+                      (while (and not-found (< i words-length))
+                        (cond
+                         ((match-string-no-properties (1+ i))
+                          (setq i (1- i))
+                          (setq not-found nil))
+                         (t
+                          (setq i (1+ i)))))
+
+                      ;; Move the current word last.
+                      (setq i (mod (1+ i) words-length))
+                      (let ((word-orig (buffer-substring-no-properties beg 
end)))
+                        ;; Match the case of the existing word (when case is 
folded).
+                        (when arg-case-fold
+                          (setq arg-words
+                                (cond
+                                 ((string-equal (upcase word-orig) word-orig)
                                   (mapcar (lambda (w) (upcase w)) arg-words))
-                                ((string-equal (downcase word-orig) word-orig)
+                                 ((string-equal (downcase word-orig) word-orig)
                                   (mapcar (lambda (w) (downcase w)) arg-words))
-                                (t
-                                  (mapcar
-                                    (lambda (w) (upcase-initials (downcase 
w))) arg-words)))))
+                                 (t
+                                  (mapcar (lambda (w) (upcase-initials 
(downcase w))) arg-words)))))
 
-                          (setq arg-words
-                            (append (seq-subseq arg-words i) (seq-subseq 
arg-words 0 i)))
+                        (setq arg-words
+                              (append (seq-subseq arg-words i) (seq-subseq 
arg-words 0 i)))
 
-                          ;; Include this literal word
-                          ;; in case of minor differences in case or spacing.
-                          (setq arg-words (cons word-orig (cdr arg-words)))
+                        ;; Include this literal word
+                        ;; in case of minor differences in case or spacing.
+                        (setq arg-words (cons word-orig (cdr arg-words)))
 
-                          (unless (string-equal (downcase (car arg-words)) 
(downcase word-orig))
-                            (error "Internal error"))))
+                        (unless (string-equal (downcase (car arg-words)) 
(downcase word-orig))
+                          (error "Internal error"))))
 
-                      (setq result (cons arg-words (cons beg end)))))))))))
+                    (setq result (cons arg-words (cons beg end)))))))))))
       (setq cycle-data-index (1+ cycle-data-index)))
 
     (or result (cons nil nil))))
@@ -247,14 +235,14 @@ Each list item can contain keyword/value pairs:
 (defun cycle-at-point--impl-cycle-get-data-for-mode ()
   "Return data associated with a major mode."
   (cond
-    (cycle-at-point-list
-      cycle-at-point-list)
-    (t
-      (let ((preset (cycle-at-point-preset nil t)))
-        (unless preset
-          ;; TODO: detect language.
-          (setq preset (cycle-at-point-preset "lang-en")))
-        preset))))
+   (cycle-at-point-list
+    cycle-at-point-list)
+   (t
+    (let ((preset (cycle-at-point-preset nil t)))
+      (unless preset
+        ;; TODO: detect language.
+        (setq preset (cycle-at-point-preset "lang-en")))
+      preset))))
 
 (defun cycle-at-point-impl (cycle-index fn-cache)
   "Cycle case styles using the choice at CYCLE-INDEX.
@@ -264,23 +252,23 @@ Argument FN-CACHE stores the result for reuse."
     (unless result-choices
       (let ((cycle-data (cycle-at-point--impl-cycle-get-data-for-mode)))
         (cond
-          ((null cycle-data)
-            (message "No cycle for mode %S" major-mode))
-          (t
-            (pcase-let ((`(,words . (,beg . ,end)) 
(cycle-at-point--cycle-words cycle-data)))
-              (cond
-                ((null words)
-                  (message "No cycle symbol found at point!"))
-                (t
-                  (let ((target (buffer-substring-no-properties beg end)))
-                    (cond
-                      ((null target)
-                        ;; Trim the string since it can contain newlines.
-                        (message "No cycle for %S found!" (string-trim 
target)))
-                      (t
-                        (setq result-choices words)
-                        (setq word-beg beg)
-                        (setq word-end end))))))))))
+         ((null cycle-data)
+          (message "No cycle for mode %S" major-mode))
+         (t
+          (pcase-let ((`(,words . (,beg . ,end)) (cycle-at-point--cycle-words 
cycle-data)))
+            (cond
+             ((null words)
+              (message "No cycle symbol found at point!"))
+             (t
+              (let ((target (buffer-substring-no-properties beg end)))
+                (cond
+                 ((null target)
+                  ;; Trim the string since it can contain newlines.
+                  (message "No cycle for %S found!" (string-trim target)))
+                 (t
+                  (setq result-choices words)
+                  (setq word-beg beg)
+                  (setq word-end end))))))))))
 
       (when result-choices
         (setq fn-cache (list result-choices word-beg word-end))))
@@ -304,15 +292,14 @@ when the preset isn't found."
   (unless preset-id
     (setq preset-id (symbol-name major-mode)))
   (let ((preset-sym (intern (concat "cycle-at-point-preset-" preset-id))))
-    (when
-      (condition-case err
-        (progn
-          (require preset-sym)
-          t)
-        (error
-          (unless quiet
-            (message "cycle-at-point: preset %S not found! (%S)" preset-id 
err))
-          nil))
+    (when (condition-case err
+              (progn
+                (require preset-sym)
+                t)
+            (error
+             (unless quiet
+               (message "cycle-at-point: preset %S not found! (%S)" preset-id 
err))
+             nil))
       (funcall preset-sym))))
 
 ;;;###autoload
diff --git a/tests/cycle-at-point-tests.el b/tests/cycle-at-point-tests.el
index a675e13623..97c94d1585 100644
--- a/tests/cycle-at-point-tests.el
+++ b/tests/cycle-at-point-tests.el
@@ -38,15 +38,14 @@
 ;; Simplify test declaration.
 (defmacro ert-deftest-decl-pair (test-id text-initial text-expected char-index 
mode)
   "Create a test named TEST-ID using TEXT-INITIAL TEXT-EXPECTED as a result."
-  `
-  (ert-deftest ,test-id ()
-    (with-temp-buffer
-      (buffer-enable-undo)
-      (funcall ,mode)
-      (insert ,text-initial)
-      (goto-char (+ (point-min) ,char-index))
-      (call-interactively 'cycle-at-point)
-      (should (equal ,text-expected (buffer-string))))))
+  `(ert-deftest ,test-id ()
+     (with-temp-buffer
+       (buffer-enable-undo)
+       (funcall ,mode)
+       (insert ,text-initial)
+       (goto-char (+ (point-min) ,char-index))
+       (call-interactively 'cycle-at-point)
+       (should (equal ,text-expected (buffer-string))))))
 
 ;; ---------------------------------------------------------------------------
 ;; Test (Basic)



reply via email to

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