Skip to content

Commit b95a5d1

Browse files
committed
* lisp/allout.el, lisp/allout-widgets.el: Use cl-lib and pcase
1 parent 03feb93 commit b95a5d1

File tree

2 files changed

+63
-72
lines changed

2 files changed

+63
-72
lines changed

lisp/allout-widgets.el

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@
7070
(require 'allout)
7171
(require 'widget)
7272
(require 'wid-edit)
73-
74-
(eval-when-compile
75-
(progn
76-
(require 'overlay)
77-
(require 'cl)
78-
))
73+
(eval-when-compile (require 'cl-lib))
7974

8075
;;;_ : internal variables needed before user-customization variables
8176
;;; In order to enable activation of allout-widgets-mode via customization,
@@ -960,7 +955,7 @@ posting threshold criteria."
960955
(when changes-pending
961956
(while changes-record
962957
(setq entry (pop changes-record))
963-
(case (car entry)
958+
(pcase (car entry)
964959
(:exposed (push entry exposures))
965960
(:added (push entry additions))
966961
(:deleted (push entry deletions))
@@ -1378,34 +1373,34 @@ FROM and TO must be in increasing order, as must be the pairs in RANGES."
13781373

13791374
;; fresh:
13801375
(setq ranges nil)
1381-
(assert (equal (funcall try 3 5) '(nil ((3 5)))))
1376+
(cl-assert (equal (funcall try 3 5) '(nil ((3 5)))))
13821377
;; add range at end:
1383-
(assert (equal (funcall try 10 12) '(nil ((3 5) (10 12)))))
1378+
(cl-assert (equal (funcall try 10 12) '(nil ((3 5) (10 12)))))
13841379
;; add range at beginning:
1385-
(assert (equal (funcall try 1 2) '(nil ((1 2) (3 5) (10 12)))))
1380+
(cl-assert (equal (funcall try 1 2) '(nil ((1 2) (3 5) (10 12)))))
13861381
;; insert range somewhere in the middle:
1387-
(assert (equal (funcall try 7 9) '(nil ((1 2) (3 5) (7 9) (10 12)))))
1382+
(cl-assert (equal (funcall try 7 9) '(nil ((1 2) (3 5) (7 9) (10 12)))))
13881383
;; consolidate some:
1389-
(assert (equal (funcall try 5 8) '(t ((1 2) (3 9) (10 12)))))
1384+
(cl-assert (equal (funcall try 5 8) '(t ((1 2) (3 9) (10 12)))))
13901385
;; add more:
1391-
(assert (equal (funcall try 15 17) '(nil ((1 2) (3 9) (10 12) (15 17)))))
1386+
(cl-assert (equal (funcall try 15 17) '(nil ((1 2) (3 9) (10 12) (15 17)))))
13921387
;; add more:
1393-
(assert (equal (funcall try 20 22)
1388+
(cl-assert (equal (funcall try 20 22)
13941389
'(nil ((1 2) (3 9) (10 12) (15 17) (20 22)))))
13951390
;; encompass more:
1396-
(assert (equal (funcall try 4 11) '(t ((1 2) (3 12) (15 17) (20 22)))))
1391+
(cl-assert (equal (funcall try 4 11) '(t ((1 2) (3 12) (15 17) (20 22)))))
13971392
;; encompass all:
1398-
(assert (equal (funcall try 2 25) '(t ((1 25)))))
1393+
(cl-assert (equal (funcall try 2 25) '(t ((1 25)))))
13991394

14001395
;; fresh slate:
14011396
(setq ranges nil)
1402-
(assert (equal (funcall try 20 25) '(nil ((20 25)))))
1403-
(assert (equal (funcall try 30 35) '(nil ((20 25) (30 35)))))
1404-
(assert (equal (funcall try 26 28) '(nil ((20 25) (26 28) (30 35)))))
1405-
(assert (equal (funcall try 15 20) '(t ((15 25) (26 28) (30 35)))))
1406-
(assert (equal (funcall try 10 30) '(t ((10 35)))))
1407-
(assert (equal (funcall try 5 6) '(nil ((5 6) (10 35)))))
1408-
(assert (equal (funcall try 2 100) '(t ((2 100)))))
1397+
(cl-assert (equal (funcall try 20 25) '(nil ((20 25)))))
1398+
(cl-assert (equal (funcall try 30 35) '(nil ((20 25) (30 35)))))
1399+
(cl-assert (equal (funcall try 26 28) '(nil ((20 25) (26 28) (30 35)))))
1400+
(cl-assert (equal (funcall try 15 20) '(t ((15 25) (26 28) (30 35)))))
1401+
(cl-assert (equal (funcall try 10 30) '(t ((10 35)))))
1402+
(cl-assert (equal (funcall try 5 6) '(nil ((5 6) (10 35)))))
1403+
(cl-assert (equal (funcall try 2 100) '(t ((2 100)))))
14091404

14101405
(setq ranges nil)
14111406
))

lisp/allout.el

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@
7979

8080
;;;_* Dependency loads
8181
(require 'overlay)
82-
(eval-when-compile
83-
;; `cl' is required for `assert'. `assert' is not covered by a standard
84-
;; autoload, but it is a macro, so that eval-when-compile is sufficient
85-
;; to byte-compile it in, or to do the require when the buffer evalled.
86-
(require 'cl)
87-
)
82+
(eval-when-compile (require 'cl-lib))
8883

8984
;;;_* USER CUSTOMIZATION VARIABLES:
9085

@@ -6122,13 +6117,13 @@ signal."
61226117
(point-max))))
61236118
;; determine key mode and, if keypair, recipients:
61246119
(setq recipients
6125-
(case keypair-mode
6120+
(pcase keypair-mode
61266121

6127-
(decrypting nil)
6122+
('decrypting nil)
61286123

6129-
(default (if encrypt-to (epg-list-keys epg-context encrypt-to)))
6124+
('default (if encrypt-to (epg-list-keys epg-context encrypt-to)))
61306125

6131-
((prompt prompt-save)
6126+
((or 'prompt 'prompt-save)
61326127
(save-window-excursion
61336128
(epa-select-keys epg-context keypair-message)))))
61346129

@@ -6786,6 +6781,7 @@ To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
67866781
(defvar allout-tests-locally-true nil
67876782
"Fodder for allout resumptions tests -- defvar just for byte compiler.")
67886783
(defun allout-test-resumptions ()
6784+
;; FIXME: Use ERT.
67896785
"Exercise allout resumptions."
67906786
;; for each resumption case, we also test that the right local/global
67916787
;; scopes are affected during resumption effects:
@@ -6794,48 +6790,48 @@ To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
67946790
(with-temp-buffer
67956791
(allout-tests-obliterate-variable 'allout-tests-globally-unbound)
67966792
(allout-add-resumptions '(allout-tests-globally-unbound t))
6797-
(assert (not (default-boundp 'allout-tests-globally-unbound)))
6798-
(assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6799-
(assert (boundp 'allout-tests-globally-unbound))
6800-
(assert (equal allout-tests-globally-unbound t))
6793+
(cl-assert (not (default-boundp 'allout-tests-globally-unbound)))
6794+
(cl-assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6795+
(cl-assert (boundp 'allout-tests-globally-unbound))
6796+
(cl-assert (equal allout-tests-globally-unbound t))
68016797
(allout-do-resumptions)
6802-
(assert (not (local-variable-p 'allout-tests-globally-unbound
6798+
(cl-assert (not (local-variable-p 'allout-tests-globally-unbound
68036799
(current-buffer))))
6804-
(assert (not (boundp 'allout-tests-globally-unbound))))
6800+
(cl-assert (not (boundp 'allout-tests-globally-unbound))))
68056801

68066802
;; ensure that variable with prior global value is resumed
68076803
(with-temp-buffer
68086804
(allout-tests-obliterate-variable 'allout-tests-globally-true)
68096805
(setq allout-tests-globally-true t)
68106806
(allout-add-resumptions '(allout-tests-globally-true nil))
6811-
(assert (equal (default-value 'allout-tests-globally-true) t))
6812-
(assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6813-
(assert (equal allout-tests-globally-true nil))
6807+
(cl-assert (equal (default-value 'allout-tests-globally-true) t))
6808+
(cl-assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6809+
(cl-assert (equal allout-tests-globally-true nil))
68146810
(allout-do-resumptions)
6815-
(assert (not (local-variable-p 'allout-tests-globally-true
6811+
(cl-assert (not (local-variable-p 'allout-tests-globally-true
68166812
(current-buffer))))
6817-
(assert (boundp 'allout-tests-globally-true))
6818-
(assert (equal allout-tests-globally-true t)))
6813+
(cl-assert (boundp 'allout-tests-globally-true))
6814+
(cl-assert (equal allout-tests-globally-true t)))
68196815

68206816
;; ensure that prior local value is resumed
68216817
(with-temp-buffer
68226818
(allout-tests-obliterate-variable 'allout-tests-locally-true)
68236819
(set (make-local-variable 'allout-tests-locally-true) t)
6824-
(assert (not (default-boundp 'allout-tests-locally-true))
6820+
(cl-assert (not (default-boundp 'allout-tests-locally-true))
68256821
nil (concat "Test setup mistake -- variable supposed to"
68266822
" not have global binding, but it does."))
6827-
(assert (local-variable-p 'allout-tests-locally-true (current-buffer))
6823+
(cl-assert (local-variable-p 'allout-tests-locally-true (current-buffer))
68286824
nil (concat "Test setup mistake -- variable supposed to have"
68296825
" local binding, but it lacks one."))
68306826
(allout-add-resumptions '(allout-tests-locally-true nil))
6831-
(assert (not (default-boundp 'allout-tests-locally-true)))
6832-
(assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6833-
(assert (equal allout-tests-locally-true nil))
6827+
(cl-assert (not (default-boundp 'allout-tests-locally-true)))
6828+
(cl-assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6829+
(cl-assert (equal allout-tests-locally-true nil))
68346830
(allout-do-resumptions)
6835-
(assert (boundp 'allout-tests-locally-true))
6836-
(assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6837-
(assert (equal allout-tests-locally-true t))
6838-
(assert (not (default-boundp 'allout-tests-locally-true))))
6831+
(cl-assert (boundp 'allout-tests-locally-true))
6832+
(cl-assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6833+
(cl-assert (equal allout-tests-locally-true t))
6834+
(cl-assert (not (default-boundp 'allout-tests-locally-true))))
68396835

68406836
;; ensure that last of multiple resumptions holds, for various scopes.
68416837
(with-temp-buffer
@@ -6851,27 +6847,27 @@ To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
68516847
'(allout-tests-globally-true 3)
68526848
'(allout-tests-locally-true 4))
68536849
;; reestablish many of the basic conditions are maintained after re-add:
6854-
(assert (not (default-boundp 'allout-tests-globally-unbound)))
6855-
(assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6856-
(assert (equal allout-tests-globally-unbound 2))
6857-
(assert (default-boundp 'allout-tests-globally-true))
6858-
(assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6859-
(assert (equal allout-tests-globally-true 3))
6860-
(assert (not (default-boundp 'allout-tests-locally-true)))
6861-
(assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6862-
(assert (equal allout-tests-locally-true 4))
6850+
(cl-assert (not (default-boundp 'allout-tests-globally-unbound)))
6851+
(cl-assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
6852+
(cl-assert (equal allout-tests-globally-unbound 2))
6853+
(cl-assert (default-boundp 'allout-tests-globally-true))
6854+
(cl-assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
6855+
(cl-assert (equal allout-tests-globally-true 3))
6856+
(cl-assert (not (default-boundp 'allout-tests-locally-true)))
6857+
(cl-assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6858+
(cl-assert (equal allout-tests-locally-true 4))
68636859
(allout-do-resumptions)
6864-
(assert (not (local-variable-p 'allout-tests-globally-unbound
6860+
(cl-assert (not (local-variable-p 'allout-tests-globally-unbound
68656861
(current-buffer))))
6866-
(assert (not (boundp 'allout-tests-globally-unbound)))
6867-
(assert (not (local-variable-p 'allout-tests-globally-true
6862+
(cl-assert (not (boundp 'allout-tests-globally-unbound)))
6863+
(cl-assert (not (local-variable-p 'allout-tests-globally-true
68686864
(current-buffer))))
6869-
(assert (boundp 'allout-tests-globally-true))
6870-
(assert (equal allout-tests-globally-true t))
6871-
(assert (boundp 'allout-tests-locally-true))
6872-
(assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6873-
(assert (equal allout-tests-locally-true t))
6874-
(assert (not (default-boundp 'allout-tests-locally-true))))
6865+
(cl-assert (boundp 'allout-tests-globally-true))
6866+
(cl-assert (equal allout-tests-globally-true t))
6867+
(cl-assert (boundp 'allout-tests-locally-true))
6868+
(cl-assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
6869+
(cl-assert (equal allout-tests-locally-true t))
6870+
(cl-assert (not (default-boundp 'allout-tests-locally-true))))
68756871

68766872
;; ensure that deliberately unbinding registered variables doesn't foul things
68776873
(with-temp-buffer

0 commit comments

Comments
 (0)