Refactor; replace/fix interactive-only & looking-back calls

This commit is contained in:
Henrik Lissner 2017-02-13 04:43:31 -05:00
parent b4e9f1312d
commit d2a0e40ca4

View file

@ -45,7 +45,7 @@ If already there, do nothing."
(funcall goto-char-fn eoc))))) (funcall goto-char-fn eoc)))))
(defun doom--surrounded-p () (defun doom--surrounded-p ()
(and (looking-back "[[{(]\\(\s+\\|\n\\)?\\(\s\\|\t\\)*") (and (looking-back "[[{(]\\(\s+\\|\n\\)?\\(\s\\|\t\\)*" (line-beginning-position))
(let* ((whitespace (match-string 1)) (let* ((whitespace (match-string 1))
(match-str (concat whitespace (match-string 2) "[])}]"))) (match-str (concat whitespace (match-string 2) "[])}]")))
(looking-at-p match-str)))) (looking-at-p match-str))))
@ -67,7 +67,7 @@ If already there, do nothing."
(if indent-tabs-mode (if indent-tabs-mode
(call-interactively 'backward-delete-char) (call-interactively 'backward-delete-char)
(save-excursion (save-excursion
(unless (looking-back "^[\s\t]*") (unless (looking-back "^[\s\t]*" (line-beginning-position))
(doom--goto-first-non-blank)) (doom--goto-first-non-blank))
(let* ((movement (% (current-column) tab-width)) (let* ((movement (% (current-column) tab-width))
(spaces (if (= 0 movement) tab-width (- tab-width movement)))) (spaces (if (= 0 movement) tab-width (- tab-width movement))))
@ -101,7 +101,7 @@ possible, or just one char if that's not possible."
(setq close-len (- (match-beginning 0) (match-end 0)))) (setq close-len (- (match-beginning 0) (match-end 0))))
(string= (plist-get (sp-get-thing t) :op) (string= (plist-get (sp-get-thing t) :op)
(plist-get (sp-get-thing) :cl))) (plist-get (sp-get-thing) :cl)))
(delete-backward-char open-len) (delete-char (- 0 open-len))
(delete-char close-len)) (delete-char close-len))
;; Delete up to the nearest tab column IF only whitespace between ;; Delete up to the nearest tab column IF only whitespace between
;; point and bol. ;; point and bol.
@ -113,7 +113,7 @@ possible, or just one char if that's not possible."
(save-match-data (save-match-data
(if (string-match "\\w*\\(\\s-+\\)$" (if (string-match "\\w*\\(\\s-+\\)$"
(buffer-substring-no-properties (- p movement) p)) (buffer-substring-no-properties (- p movement) p))
(delete-backward-char (- (match-end 1) (match-beginning 1))) (delete-char (- 0 (- (match-end 1) (match-beginning 1))))
(call-interactively 'delete-backward-char))))) (call-interactively 'delete-backward-char)))))
;; Otherwise do a regular delete ;; Otherwise do a regular delete
(t (call-interactively 'delete-backward-char))))) (t (call-interactively 'delete-backward-char)))))