Skip to content

Commit c97ed64

Browse files
committed
Merge pull request #1180 from Malabarba/small-things-all-around
Small things all around
2 parents c895d83 + eabfac8 commit c97ed64

File tree

6 files changed

+72
-46
lines changed

6 files changed

+72
-46
lines changed

cider-debug.el

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,31 @@
2929
(require 'cider-interaction)
3030
(require 'dash)
3131

32+
33+
;;; Customization
34+
(defgroup cider-debug nil
35+
"Presentation and behaviour of the cider debugger."
36+
:prefix "cider-debug-"
37+
:package-version '(cider-debug . "0.10.0"))
38+
3239
(defface cider-result-overlay-face
3340
'((((class color) (background light)) :foreground "firebrick")
3441
(((class color) (background dark)) :foreground "orange red"))
3542
"Face used to display result of debug step at point."
36-
:group 'cider
43+
:group 'cider-debug
3744
:package-version "0.9.1")
3845

3946
(defface cider-debug-code-overlay-face
4047
'((((class color) (background light)) :background "grey80")
4148
(((class color) (background dark)) :background "grey30"))
4249
"Face used to mark code being debugged."
43-
:group 'cider
50+
:group 'cider-debug
4451
:package-version "0.9.1")
4552

4653
(defface cider-debug-prompt-face
4754
'((t :underline t :inherit font-lock-builtin-face))
4855
"Face used to mark code being debugged."
49-
:group 'cider
56+
:group 'cider-debug
5057
:package-version "0.10.0")
5158

5259
(defcustom cider-debug-use-overlays 'end-of-line
@@ -57,7 +64,7 @@ Possible values are inline, end-of-line, or nil."
5764
:type '(choice (const :tag "End of line" end-of-line)
5865
(const :tag "Inline" inline)
5966
(const :tag "No overlays" nil))
60-
:group 'cider
67+
:group 'cider-debug
6168
:package-version "0.9.1")
6269

6370

@@ -103,7 +110,7 @@ is displayed at point."
103110
#'cider--make-overlay
104111
(line-beginning-position)
105112
(if (eq where 'inline) (point) (line-end-position))
106-
'debug-result
113+
type
107114
'after-string
108115
(propertize (concat (propertize " " 'cursor 1000)
109116
cider-interactive-eval-result-prefix
@@ -126,7 +133,7 @@ is displayed at point."
126133
(cider--make-result-overlay value 'debug-result cider-debug-use-overlays
127134
'before-string cider--fringe-arrow-string)
128135
;; Code
129-
(cider--make-overlay (save-excursion (forward-sexp -1) (point))
136+
(cider--make-overlay (save-excursion (clojure-backward-logical-sexp 1) (point))
130137
(point) 'debug-code
131138
'face 'cider-debug-code-overlay-face
132139
;; Higher priority than `show-paren'.
@@ -146,7 +153,7 @@ Set by `cider--turn-on-debug-mode'.")
146153
"If non-nil, local variables are displayed while debugging.
147154
Can be toggled at any time with `\\[cider-debug-toggle-locals]'."
148155
:type 'boolean
149-
:group 'cider
156+
:group 'cider-debug
150157
:package-version '(cider . "0.10.0"))
151158

152159
(defun cider--debug-format-locals-list (locals)
@@ -274,20 +281,6 @@ ID is the id of the message that instrumented CODE."
274281
(set-buffer-modified-p nil))))
275282
(switch-to-buffer buffer-name)))
276283

277-
(defun cider--forward-sexp (n)
278-
"Move forward N logical sexps.
279-
This will skip over sexps that don't represent objects, such as ^hints and
280-
#reader.macros."
281-
(while (> n 0)
282-
;; Non-logical sexps.
283-
(while (progn (forward-sexp 1)
284-
(forward-sexp -1)
285-
(looking-at-p "\\^\\|#[[:alpha:]]"))
286-
(forward-sexp 1))
287-
;; The actual sexp
288-
(forward-sexp 1)
289-
(setq n (1- n))))
290-
291284
(defun cider--debug-goto-keyval (key)
292285
"Find KEY in current sexp or return nil."
293286
(-when-let (limit (ignore-errors (save-excursion (up-list) (point))))
@@ -311,12 +304,12 @@ sexp."
311304
;; String coordinates are map keys.
312305
(if (stringp next)
313306
(cider--debug-goto-keyval next)
314-
(cider--forward-sexp next)))
307+
(clojure-forward-logical-sexp (pop coordinates))))
315308
;; If that extra pop was the last coordinate, this represents the
316309
;; entire #(...), so we should move back out.
317310
(backward-up-list)))
318311
;; Place point at the end of instrumented sexp.
319-
(cider--forward-sexp 1))
312+
(clojure-forward-logical-sexp 1))
320313
;; Avoid throwing actual errors, since this happens on every breakpoint.
321314
(error (message "Can't find instrumented sexp, did you edit the source?"))))
322315

cider-doc.el

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,15 @@
175175
"Open the source for the current symbol, if available."
176176
(interactive)
177177
(if cider-docview-file
178-
(let ((buffer (and cider-docview-file
179-
(not (cider--tooling-file-p cider-docview-file))
180-
(cider-find-file cider-docview-file))))
181-
(cider-jump-to buffer (cons cider-docview-line nil) nil))
178+
(-if-let (buffer (and (not (cider--tooling-file-p cider-docview-file))
179+
(cider-find-file cider-docview-file)))
180+
(cider-jump-to buffer (if cider-docview-line
181+
(cons cider-docview-line nil)
182+
cider-docview-symbol)
183+
nil)
184+
(user-error
185+
(substitute-command-keys
186+
"Can't find the source because it wasn't defined with `cider-eval-buffer'")))
182187
(error "No source location for %s" cider-docview-symbol)))
183188

184189
(defun cider-docview-grimoire ()

cider-interaction.el

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ When invoked with a prefix ARG the command doesn't prompt for confirmation."
631631
"Return the sexp preceding the point."
632632
(buffer-substring-no-properties
633633
(save-excursion
634-
(backward-sexp)
634+
(clojure-backward-logical-sexp 1)
635635
(point))
636636
(point)))
637637

@@ -773,9 +773,12 @@ not found."
773773

774774
(defun cider-jump-to (buffer &optional pos other-window)
775775
"Push current point onto marker ring, and jump to BUFFER and POS.
776-
POS can be either a numeric position in BUFFER or a cons (LINE . COLUMN)
777-
where COLUMN can be nil. If OTHER-WINDOW is non-nil don't reuse current
778-
window."
776+
POS can be either a number, a cons, or a symbol.
777+
If a number, it is the character position (the point).
778+
If a cons, it specifies the position as (LINE . COLUMN). COLUMN can be nil.
779+
If a symbol, `cider-jump-to' searches for something that looks like the
780+
symbol's definition in the file.
781+
If OTHER-WINDOW is non-nil don't reuse current window."
779782
(ring-insert find-tag-marker-ring (point-marker))
780783
(if other-window
781784
(pop-to-buffer buffer)
@@ -785,14 +788,33 @@ window."
785788
(widen)
786789
(goto-char (point-min))
787790
(cider-mode +1)
788-
(if (consp pos)
789-
(progn
790-
(forward-line (1- (or (car pos) 1)))
791-
(if (cdr pos)
792-
(move-to-column (cdr pos))
793-
(back-to-indentation)))
794-
(when pos
795-
(goto-char pos)))))
791+
(cond
792+
;; Line-column specification.
793+
((consp pos)
794+
(forward-line (1- (or (car pos) 1)))
795+
(if (cdr pos)
796+
(move-to-column (cdr pos))
797+
(back-to-indentation)))
798+
;; Point specification.
799+
((numberp pos)
800+
(goto-char pos))
801+
;; Symbol or string.
802+
(pos
803+
;; Try to find (def full-name ...).
804+
(if (or (save-excursion
805+
(search-forward-regexp (format "(def.*\\s-\\(%s\\)" (regexp-quote pos))
806+
nil 'noerror))
807+
(let ((name (replace-regexp-in-string ".*/" "" pos)))
808+
;; Try to find (def name ...).
809+
(or (save-excursion
810+
(search-forward-regexp (format "(def.*\\s-\\(%s\\)" (regexp-quote name))
811+
nil 'noerror))
812+
;; Last resort, just find the first occurrence of `name'.
813+
(save-excursion
814+
(search-forward name nil 'noerror)))))
815+
(goto-char (match-beginning 0))
816+
(message "Can't find %s in %s" pos (buffer-file-name))))
817+
(t nil))))
796818

797819
(defun cider-find-dwim-other-window (symbol-file)
798820
"Jump to SYMBOL-FILE at point, place results in other window."
@@ -905,11 +927,12 @@ INFO object is returned by `cider-var-info' or `cider-member-info'.
905927
OTHER-WINDOW is passed to `cider-jamp-to'."
906928
(let* ((line (nrepl-dict-get info "line"))
907929
(file (nrepl-dict-get info "file"))
930+
(name (nrepl-dict-get info "name"))
908931
(buffer (and file
909932
(not (cider--tooling-file-p file))
910933
(cider-find-file file))))
911934
(if buffer
912-
(cider-jump-to buffer (cons line nil) other-window)
935+
(cider-jump-to buffer (if line (cons line nil) name) other-window)
913936
(error "No source location"))))
914937

915938
(defun cider--find-var-other-window (var &optional line)
@@ -1692,7 +1715,7 @@ If invoked with a PREFIX argument, print the result in the current buffer."
16921715
(interactive "P")
16931716
(cider-interactive-eval (cider-last-sexp)
16941717
(when prefix (cider-eval-print-handler))
1695-
(save-excursion (backward-sexp 1) (point))))
1718+
(save-excursion (clojure-backward-logical-sexp 1) (point))))
16961719

16971720
(defun cider-eval-last-sexp-and-replace ()
16981721
"Evaluate the expression preceding point and replace it with its result."

cider-macroexpansion.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ This variable specifies both what was expanded and the expander.")
101101
"Substitute the form preceding point with its macroexpansion using EXPANDER."
102102
(interactive)
103103
(let* ((expansion (cider-sync-request:macroexpand expander (cider-last-sexp)))
104-
(bounds (cons (save-excursion (backward-sexp) (point)) (point))))
104+
(bounds (cons (save-excursion (clojure-backward-logical-sexp 1) (point)) (point))))
105105
(cider-redraw-macroexpansion-buffer
106106
expansion (current-buffer) (car bounds) (cdr bounds))))
107107

cider-stacktrace.el

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,17 @@ it wraps to 0."
422422
(info (or (and var (cider-var-info var))
423423
(and class method (cider-member-info class method))
424424
(nrepl-dict)))
425-
;; stacktrace returns more accurate line numbers
426-
(info (nrepl-dict-put info "line" (button-get button 'line)))
425+
;; Stacktrace returns more accurate line numbers, but if the function's
426+
;; line was unreliable, then so is the stacktrace by the same amount.
427+
;; Set `line-shift' to the number of lines from the beginning of defn.
428+
(line-shift (- (or (button-get button 'line) 0)
429+
(or (nrepl-dict-get info "line") 1)))
427430
;; give priority to `info` files as `info` returns full paths.
428431
(info (nrepl-dict-put info "file" (or (nrepl-dict-get info "file")
429432
(button-get button 'file)))))
430-
(cider--jump-to-loc-from-info info t)))
433+
(cider--jump-to-loc-from-info info t)
434+
(forward-line line-shift)
435+
(back-to-indentation)))
431436

432437
(defun cider-stacktrace-jump (&optional arg)
433438
"Like `cider-find-var', but uses the stack frame source at point, if available."

cider.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
;; Maintainer: Bozhidar Batsov <[email protected]>
1212
;; URL: http://www.github.com/clojure-emacs/cider
1313
;; Version: 0.10.0-cvs
14-
;; Package-Requires: ((clojure-mode "4.0.0") (dash "2.4.1") (pkg-info "0.4") (emacs "24.3") (queue "0.1.1"))
14+
;; Package-Requires: ((clojure-mode "4.2.0") (dash "2.4.1") (pkg-info "0.4") (emacs "24.3") (queue "0.1.1"))
1515
;; Keywords: languages, clojure, cider
1616

1717
;; This program is free software: you can redistribute it and/or modify

0 commit comments

Comments
 (0)