clojure-emacs / clojure-emacs/cider

Idea: make more commands work with point at beginning of sexp

Open
#2,829 7 comments 0 reactions 0 assignees View on GitHub
enhancement pinned
Dominant language
Emacs Lisp
Stars
3.7k
Forks
651
Avg merge
11h 6m
Merged PRs (30d)
33

Description

**Is your feature request related to a problem? Please describe.**

I usually want to call commands like `cider-inspect`, and `cider-macroexpand` with my cursor point at the beginning or middle of a form, instead of at the end like Cider expects.

**Describe the solution you'd like**

It's mainly a personal preference and habit, so I had `cider-last-sexp` edited to the following, which moves the point to the appropriate position. Because lots of commands use this under the hood, it automatically makes them able to work with the point at beginning of a paren or symbol.

```elisp
(defun cider-last-sexp (&optional bounds)
"Return the sexp preceding the point.
If BOUNDS is non-nil, return a list of its starting and ending position
instead."
(apply (if bounds #'list #'buffer-substring-no-properties)
(save-excursion
(unless (eq (point) (cdr (bounds-of-thing-at-point 'sexp))) ;; <== added
(forward-sexp 1)) ;; <== added
(clojure-backward-logical-sexp 1)
(list (point)
(progn (clojure-forward-logical-sexp 1)
(skip-chars-forward "[:blank:]")
(when (looking-at-p "\n") (forward-char 1))
(point))))))
```

**Describe alternatives you've considered**
nil

**Additional context**
This fix means that the command names and docstrings are no longer accurate - should be something like "sexp at point" instead of "preceding sexp"

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.