Fixed the s-expression text objects

I really use this a lot while programming Emacs Lisp.
This commit is contained in:
Howard Abrams 2023-12-19 20:11:35 -08:00
parent 1022f21d29
commit ded7a58da0
4 changed files with 30 additions and 21 deletions

View file

@ -474,27 +474,32 @@ Typing ~d a a~ will delete the argument leaving:
return a + b + c
#+end_src
*** Better Parenthesis with Text Object
I took the following clever idea and code from [[http://blog.binchen.org/posts/code-faster-by-extending-emacs-evil-text-object/][this essay]] from Chen Bin for creating a ~xig~ to grab code within any grouping characters, like parens, braces and brackets. For instance, ~dig~ cuts the content inside brackets, etc. First, we need a function to do the work (I changed the original from =my-= to =ha-= so that it is easier for me to distinguish functions from my configuration):
I took the following clever idea and code from [[http://blog.binchen.org/posts/code-faster-by-extending-emacs-evil-text-object/][this essay]] from Chen Bin for creating a ~xix~ to grab code within any grouping characters, like parens, braces and brackets. For instance, ~dix~ cuts the content inside brackets, etc. First, we need a function to do the work (I changed the original from =my-= to =ha-= so that it is easier for me to distinguish functions from my configuration):
#+begin_src emacs-lisp
(defun ha-evil-paren-range (count beg end type inclusive)
"Get minimum range of paren text object.
COUNT, BEG, END, TYPE is used. If INCLUSIVE is t, the text object is inclusive."
(let* ((parens '("()" "[]" "{}" "<>"))
range
COUNT, BEG, END, TYPE follow Evil interface, passed to
the `evil-select-paren' function.
If INCLUSIVE is t, the text object is inclusive."
(let* ((open-rx (rx (any "(" "[" "{" "<")))
(close-rx (rx (any ")" "]" "}" ">")))
(range (condition-case nil
(evil-select-paren
open-rx close-rx
beg end type count inclusive)
(error nil)))
found-range)
(dolist (p parens)
(condition-case nil
(setq range (evil-select-paren (aref p 0) (aref p 1) beg end type count inclusive))
(error nil))
(when range
(cond
(found-range
(when (< (- (nth 1 range) (nth 0 range))
(- (nth 1 found-range) (nth 0 found-range)))
(setf (nth 0 found-range) (nth 0 range))
(setf (nth 1 found-range) (nth 1 range))))
(t
(setq found-range range)))))
(when range
(cond
(found-range
(when (< (- (nth 1 range) (nth 0 range))
(- (nth 1 found-range) (nth 0 found-range)))
(setf (nth 0 found-range) (nth 0 range))
(setf (nth 1 found-range) (nth 1 range))))
(t
(setq found-range range))))
found-range))
#+end_src

View file

@ -315,7 +315,7 @@ A feature I enjoyed from Spacemacs is the ability to evaluate the s-expression c
(eval-region (region-beginning) (region-end))
(unless (looking-at (rx (any ")" "]")))
(lispyville-next-closing))
(sp-end-of-sexp))
(if (fboundp 'eros-eval-last-sexp)
(call-interactively 'eros-eval-last-sexp)

View file

@ -19,7 +19,7 @@ A literate programming file for helping me program.
;; This file is not part of GNU Emacs.
;;
;; *NB:* Do not edit this file. Instead, edit the original literate file at:
;; ~/other/hamacs/general-programming.org
;; ~/other/hamacs/ha-programming.org
;; And tangle the file to recreate this one.
;;
;;; Code:
@ -810,10 +810,11 @@ Until I can get [[https://github.com/d12frosted/homebrew-emacs-plus/issues/222][
#+end_src
The unicode-fonts package rejigs the internal tables Emacs uses to pick better fonts for unicode codepoint ranges.
#+begin_src emacs-lisp
#+begin_src emacs-lisp :tangle no
(use-package unicode-fonts
:config
(unicode-fonts-setup))
(ignore-errors
(unicode-fonts-setup)))
#+end_src
** Compiling
The [[help:compile][compile]] function lets me enter a command to run, or I can search the history for a previous run. What it doesnt give me, is a project-specific list of commands. Perhaps, for each project, I define in =.dir-locals.el= a variable, =compile-command-list=, like:

View file

@ -286,7 +286,10 @@ Since every project perspective may have a shell terminal, lets see if I can
(s-join "/"))
(file-name-base (directory-file-name directory)))))
(format "Terminal: %s" name)))
#+end_src
Perhaps a Unit test is in order:
#+begin_src emacs-lisp :tangle no
(ert-deftest ha--terminal-name-from-dir-test ()
(should
(string= (ha-shell--name-from-dir "~/other/hamacs/") "Terminal: hamacs"))