diff --git a/configuration.org b/configuration.org index bfef215..40b5c78 100644 --- a/configuration.org +++ b/configuration.org @@ -147,6 +147,45 @@ copied to the kill ring." (copy-region-as-kill beginning end)))) #+END_SRC +*** Enclose region in a specific character + +#+BEGIN_SRC emacs-lisp +(defun æ-enclose-region (character &optional start end) + "Enclose region in CHARACTER. If region is empty, simply inserts + CHARACTER two times and moves point between them. + + If character is present in `insert-pair-alist', this function + will enclose region in the corresponding pair. In this case, + CHARACTER must be the opening member of the pair." + + (interactive "cWhat character? \nr") + + (setq open character close character) + + (let ((pair (assq character insert-pair-alist))) + (if pair + (if (nth 2 pair) + (setq open (nth 1 pair) close (nth 2 pair)) + (setq open (nth 0 pair) close (nth 1 pair))))) + + (unless (and open close) + (setq open character) + (setq close character)) + + (unless (use-region-p) + (setq start (point) end (point))) + + (save-excursion + (goto-char end) + (insert-char close) + + (goto-char start) + (insert-char open)) + + (unless (use-region-p) + (forward-char))) +#+END_SRC + ** Navigation *** Move to different beginnings of the current line diff --git a/init.el b/init.el index 89f13cb..83a9af1 100644 --- a/init.el +++ b/init.el @@ -29,7 +29,6 @@ (load "gnu-c-header") (load "round-number-to-decimals") (load "zim") -(load "enclose-string") (load "text-manip") (load "frame-manip") (load "file-manip") diff --git a/lisp/enclose-string.el b/lisp/enclose-string.el deleted file mode 100644 index ee59d6c..0000000 --- a/lisp/enclose-string.el +++ /dev/null @@ -1,34 +0,0 @@ -(defun æ-enclose-region (character &optional start end) - "Enclose region in CHARACTER. If region is empty, simply inserts - CHARACTER two times and moves point between them. - - If character is present in `insert-pair-alist', this function - will enclose region in the corresponding pair. In this case, - CHARACTER must be the opening member of the pair." - - (interactive "cWhat character? \nr") - - (setq open character close character) - - (let ((pair (assq character insert-pair-alist))) - (if pair - (if (nth 2 pair) - (setq open (nth 1 pair) close (nth 2 pair)) - (setq open (nth 0 pair) close (nth 1 pair))))) - - (unless (and open close) - (setq open character) - (setq close character)) - - (unless (use-region-p) - (setq start (point) end (point))) - - (save-excursion - (goto-char end) - (insert-char close) - - (goto-char start) - (insert-char open)) - - (unless (use-region-p) - (forward-char)))