org-dwim-char: cleanup

This commit is contained in:
MitchMarq42 2023-06-12 19:47:40 -08:00
parent 3950860dd4
commit bdcc7f5c87

View File

@ -112,8 +112,11 @@ Otherwise, insert two of CHAR and put point between them like `electric-pair'."
(let* ((char (or char (string-to-char (this-command-keys)))) (let* ((char (or char (string-to-char (this-command-keys))))
(word (thing-at-point 'word 'no-properties)) (word (thing-at-point 'word 'no-properties))
;;; test conditions here to be eval'd, separating flow from data ;;; test conditions here to be eval'd, separating flow from data
;; at beginning of line
(beginning-of-line-test '(bolp))
;; at beginning of word ;; at beginning of word
(beginning-of-word-test '(or (bolp) (eq (char-before (point)) ?\ ))) (beginning-of-word-test `(or ,beginning-of-line-test
(eq (char-before (point)) ?\ )))
;; word is surrounded by `char' ;; word is surrounded by `char'
(surrounded-by-char-test (surrounded-by-char-test
'(and (eq (char-before (beginning-of-thing 'word)) char) '(and (eq (char-before (beginning-of-thing 'word)) char)
@ -122,12 +125,11 @@ Otherwise, insert two of CHAR and put point between them like `electric-pair'."
(double-char-test (eq char (char-after))) (double-char-test (eq char (char-after)))
;; Weird Org exceptions because org ;; Weird Org exceptions because org
(org-exceptions-test (org-exceptions-test
'(or (string-match-p (rx bol (or "#" "*")) '(or (and (bolp)
(thing-at-point 'line 'no-properties)) (string-match-p (rx bol (or "#" "*"))
(thing-at-point 'line 'no-properties)))
(org-in-block-p org-protecting-blocks) (org-in-block-p org-protecting-blocks)
(org-at-property-p)) (org-at-property-p))))
)
)
(cond (cond
((eq evil-state 'visual) ((eq evil-state 'visual)
(let* ((beg (region-beginning)) (let* ((beg (region-beginning))
@ -137,19 +139,8 @@ Otherwise, insert two of CHAR and put point between them like `electric-pair'."
(if (eval beginning-of-word-test) (if (eval beginning-of-word-test)
;; run original function bound to key ;; run original function bound to key
(let ((charstr (make-string 1 char))) (let ((charstr (make-string 1 char)))
;; (pcase charstr
;; ;; TODO: can we not hard-code this?
;; ;; MAYBE: with Advice on each below function.
;; ;; MAYBE: with `key-binding' fn
;; ("_" (call-interactively 'evil-next-line-1-first-non-blank))
;; ("/" (call-interactively 'evil-search-forward))
;; ("*" (call-interactively 'evil-search-word-forward))
;; ("+" (call-interactively 'evil-next-line-first-non-blank))
;; ("~" (call-interactively 'evil-invert-char))
;; ("=" (call-interactively 'evil-indent)))
(call-interactively (alist-get charstr org-vw-old-binds-alist (call-interactively (alist-get charstr org-vw-old-binds-alist
nil nil #'string=)) nil nil #'string=)))
)
(save-excursion (save-excursion
(if (eval surrounded-by-char-test) (if (eval surrounded-by-char-test)
(progn (progn
@ -162,6 +153,8 @@ Otherwise, insert two of CHAR and put point between them like `electric-pair'."
(insert char)))))) (insert char))))))
((eval double-char-test) (right-char)) ((eval double-char-test) (right-char))
((eval org-exceptions-test) (insert char)) ((eval org-exceptions-test) (insert char))
((and (eval beginning-of-line-test) (eq char ?*))
(insert char))
(t (progn (t (progn
(insert (make-string 2 char)) (insert (make-string 2 char))
(left-char)))))) (left-char))))))
@ -175,6 +168,9 @@ Store it in the variable `org-vw-old-binds-alist'."
(cons key (key-binding key))) (cons key (key-binding key)))
mitch/org-dwim-char-chars)))) mitch/org-dwim-char-chars))))
(add-hook 'org-vw-pre-hook #'org-vw-snapshot-bindings nil 'local) (add-hook 'org-vw-pre-hook #'org-vw-snapshot-bindings nil 'local)
;; (defun org-vw-backspace)
;; (setq debug-on-error t) ;; (setq debug-on-error t)
;; --------- LET THY BRAIN NO LONGER TREMBLE, FOR I AM BECOME COMPLETE --------- ;; --------- LET THY BRAIN NO LONGER TREMBLE, FOR I AM BECOME COMPLETE ---------