summaryrefslogtreecommitdiff
path: root/emacs/scripts
diff options
context:
space:
mode:
authortslil clingman <>2020-03-04 10:30:21 -0800
committertslil clingman <>2020-03-04 10:30:21 -0800
commita8b572173842b2a1f31bc4109de59ff471a84256 (patch)
tree71c24e82b65140d163296ac7a03d6f9616ca81d0 /emacs/scripts
parentc7324352f90f11512e3a64ae712594384fb9a56a (diff)
Dropped ivy for selectrum
Diffstat (limited to 'emacs/scripts')
-rw-r--r--emacs/scripts/cdm-mode.el74
1 files changed, 17 insertions, 57 deletions
diff --git a/emacs/scripts/cdm-mode.el b/emacs/scripts/cdm-mode.el
index 5fb2c37..2e67d4d 100644
--- a/emacs/scripts/cdm-mode.el
+++ b/emacs/scripts/cdm-mode.el
@@ -1,4 +1,4 @@
-;; Time-stamp: <2020-02-26 21:47:18 (tslil@bison)>
+;; Time-stamp: <2020-03-04 10:28:56 (tslil@bison)>
(defvar cdm-arr-type-list '(("arrow" . "a")
("id" . "d")
@@ -26,7 +26,7 @@
"midway" "below right" "below left"
"above right" "above left" "none"))
-(defvar cdm--use-helm nil)
+(defvar cdm-completion-backend 'default)
(defvar cdm-mode-map
(let ((map (make-sparse-keymap)))
@@ -37,10 +37,6 @@
map))
(defvar cdm--node-list nil)
-(defvar cdm--pos-helm-source nil)
-(defvar cdm--node-helm-source nil)
-(defvar cdm--parr-dir-helm-source nil)
-(defvar cdm--arr-type-helm-source nil)
(defvar cdm--strip-label t)
@@ -75,7 +71,7 @@
(n2 (cdm--is-natural (cdr s2))))
(if (and n1 n2) (> n1 n2)
(string-lessp (cdr s1) (cdr s2)))))
-
+n
(defun cdm--strip-label-f (str)
(let ((strs (split-string str "$+")))
(if (and (= 3 (length strs))
@@ -116,31 +112,19 @@
(defun cdm--ivy-complete (prompt list)
(cdr (assoc-string (ivy-read prompt list) list)))
-(defun cdm--complete-nodes (prompt)
- (if cdm--use-helm (helm :sources cdm--node-helm-source
- :prompt prompt
- :buffer "*helm-node*")
- (cdm--ivy-complete prompt cdm--node-list)))
+(defun cdm--complete (prompt list)
+ (cond
+ ((eq cdm-completion-backend 'ivy) (cdm--ivy-complete prompt list))
+ (t (completing-read prompt list))))
(defun cdm--complete-position ()
- (let* ((prompt "Select relative position: ")
- (p (if cdm--use-helm (helm :sources cdm--pos-helm-source
- :prompt prompt
- :buffer "*helm-position*")
- (ivy-read prompt cdm--pos-list))))
+ (let ((p (cdm--complete "Select relative position: " cdm--pos-list)))
(when p
(cond
((string-equal "none" p) nil)
((string-equal "midway" p) (concat p ", from= "))
(t (concat p " of= "))))))
-(defun cdm--complete-arr-type ()
- (let ((prompt "Select arrow type: "))
- (if cdm--use-helm (helm :sources cdm--arr-type-helm-source
- :prompt prompt
- :buffer "*helm-arrow*"))
- (cdm--ivy-complete prompt cdm-arr-type-list)))
-
(defun cdm--not-so-smart-move ()
(back-to-indentation)
(unless (= (point) (line-end-position))
@@ -171,10 +155,10 @@
(let* ((name (or node-name
(read-string "New node name: " (cdm--next-name))))
(position (cdm--complete-position))
- (rel-to (when position (cdm--complete-nodes position)))
+ (rel-to (when position (cdm--complete position cdm--node-list)))
(midway-other (when (and position
(string-prefix-p "midway" position))
- (cdm--complete-nodes "midway, ending="))))
+ (cdm--complete "midway, ending=" cdm--node-list))))
(if midway-other
(cdm--insert-raw-path name rel-to midway-other ",midway" "$$" 3)
(cdm--insert-raw-node name (if rel-to (concat position rel-to) "") "$$" 3))))
@@ -225,11 +209,7 @@
(when label-props (search-backward "$}")))
(defun cdm--insert-parallel-arrows (from-node to-node &optional labelled)
- (let* ((prompt "Select parallel arrow directionality: ")
- (ty (if cdm--use-helm (helm :sources cdm--parr-dir-helm-source
- :prompt prompt
- :buffer "*helm-parr*")
- (cdm--ivy-complete prompt cdm-parr-dir-list))))
+ (let* ((ty (cdm--complete "Select parallel arrow directionality: " cdm-parr-dir-list)))
(when ty
(let ((dirs (case ty
(0 '(".east" . ".west" ))
@@ -263,14 +243,14 @@
(error "Cannot insert an arrow, no nodes found."))
(end-of-line)
;; TODO: recast i.t.o let*-unless-null
- (let ((type (cdm--complete-arr-type)))
+ (let ((type (cdm--complete "Select arrow type: " cdm-arr-type-list)))
(when type
(let* ((par (string-equal "p" type))
(cell (string-prefix-p "c" type))
(extra (when (and (not par) (not cell) extra-props)
(read-string "Extra properties: ")))
- (from-node (cdm--complete-nodes "From: "))
- (to-node (cdm--complete-nodes "To: "))
+ (from-node (cdm--complete "From: " cdm--node-list))
+ (to-node (cdm--complete "To: " cdm--node-list))
(labelled (unless (string-suffix-p "d" type)
(char-equal ?\C-m (read-char "Labelled (Return = yes)?"))))
(label-props (when (and (not par) labelled)
@@ -289,7 +269,7 @@
cdm--square-nodes nil)
(message "Square progress reset."))
-;; TODO: Orientation? This is broken with swaps if you change orientation...
+;; TODO: Orientation? This is broken with swaps if one changes orientation...
(defun cdm--prompt-insert-arrow-square (node-1 node-2 swap)
(when (cdm--get-nodes)
(let (r d)
@@ -298,7 +278,7 @@
(string-equal node-2 (cdr n)))
(add-to-list 'r n)))
(setq cdm--node-list r)
- (setq d (cdm--complete-nodes "Domain for arrow: "))
+ (setq d (cdm--complete "Domain for arrow: " cdm--node-list))
(if (string-equal d node-1)
(cdm--insert-arrow-tex d node-2 "a" swap)
(cdm--insert-arrow-tex d node-1 "a" swap)))))
@@ -324,29 +304,9 @@
(when (and (<= p 3) (>= p 0))
(add-to-list 'cdm--square-nodes s t)))))
-(defun cdm--init-helm ()
- (setq cdm--pos-helm-source (helm-build-sync-source "position"
- :candidates 'cdm--pos-list
- :fuzzy-match t
- :nomark t)
- cdm--arr-type-helm-source (helm-build-sync-source "arrow-type"
- :candidates 'cdm-arr-type-list
- :fuzzy-match t
- :nomark t)
- cdm--node-helm-source (helm-build-sync-source "nodes"
- :candidates 'cdm--node-list
- :fuzzy-match t
- :nomark t
- :multiline t)
- cdm--parr-dir-helm-source (helm-build-sync-source "parr-dir"
- :candidates 'cdm-parr-dir-list
- :fuzzy-match t
- :nomark t)))
-
(defun cdm--init ()
(require 'subr-x)
- (require 'cl)
- (if cdm--use-helm (cdm--init-helm)) )
+ (require 'cl))
(define-minor-mode cdm-mode
"Minor mode to help with commutative diagrams"