aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/lisp/my')
-rw-r--r--emacs/.emacs.d/lisp/my/my-editing.el65
1 files changed, 65 insertions, 0 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-editing.el b/emacs/.emacs.d/lisp/my/my-editing.el
index 6bbde62..f8e405e 100644
--- a/emacs/.emacs.d/lisp/my/my-editing.el
+++ b/emacs/.emacs.d/lisp/my/my-editing.el
@@ -302,6 +302,71 @@ controlled by `delete-pair-blink-delay'."
(delete-pair -1)
(delete-pair 1)))
+(defun my-delete-line-if-space-only ()
+ "Delete the current line, if it has only space and nothing else."
+ (interactive)
+ (save-excursion
+ (beginning-of-line)
+ (when (looking-at-p "^\\ *$")
+ (delete-line))))
+
+;;; To override delete-pair
+(defun my-delete-pair (&optional arg)
+ "Delete a pair of characters enclosing ARG sexps that follow point.
+
+A negative ARG deletes a pair around the preceding ARG sexps
+instead. The option `delete-pair-blink-delay' can disable
+blinking.
+
+Delete space-only-lines caused by the deletion, as well as
+re-indent the affected region."
+ (interactive "P")
+ (if arg
+ (setq arg (prefix-numeric-value arg))
+ (setq arg 1))
+ (let ((beg) (end))
+ (if (< arg 0)
+ (save-excursion
+ (skip-chars-backward " \t")
+ (save-excursion
+ (let ((close-char (char-before)))
+ (forward-sexp arg)
+ (unless (member (list (char-after) close-char)
+ (mapcar (lambda (p)
+ (if (= (length p) 3) (cdr p) p))
+ insert-pair-alist))
+ (error "Not after matching pair"))
+ (when (and (numberp delete-pair-blink-delay)
+ (> delete-pair-blink-delay 0))
+ (sit-for delete-pair-blink-delay))
+ (delete-char 1)
+ (my-delete-line-if-space-only)
+ (setq beg (point))))
+ (delete-char -1)
+ (my-delete-line-if-space-only)
+ (setq end (point)))
+ (save-excursion
+ (skip-chars-forward " \t")
+ (save-excursion
+ (let ((open-char (char-after)))
+ (forward-sexp arg)
+ (unless (member (list open-char (char-before))
+ (mapcar (lambda (p)
+ (if (= (length p) 3) (cdr p) p))
+ insert-pair-alist))
+ (error "Not before matching pair"))
+ (when (and (numberp delete-pair-blink-delay)
+ (> delete-pair-blink-delay 0))
+ (sit-for delete-pair-blink-delay))
+ (delete-char -1)
+ (my-delete-line-if-space-only)
+ (setq end (point))))
+ (delete-char 1)
+ (my-delete-line-if-space-only)
+ (setq beg (point))))
+ (when (and beg end)
+ (indent-region beg end))))
+
;;;###autoload
(defun my-zap-back-to-char (char &optional arg)
"Backward `zap-to-char' for CHAR.