Skip to content

Commit

Permalink
Sanitize our method for injecting #dbg
Browse files Browse the repository at this point in the history
  • Loading branch information
Malabarba committed Feb 5, 2016
1 parent 45d8cb4 commit 5ae5228
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions cider-debug.el
Expand Up @@ -390,7 +390,7 @@ specific message."
(defconst cider--debug-buffer-format "*cider-debug %s*")

(defun cider--debug-trim-code (code)
(replace-regexp-in-string "\\`#\\(dbg\\|break\\) ?" "" code))
(replace-regexp-in-string "\\`#[a-z]+[\n\r[:blank:]]*" "" code))

(declare-function cider-set-buffer-ns "cider-mode")
(defun cider--initialize-debug-buffer (code ns id &optional reason)
Expand Down Expand Up @@ -497,6 +497,18 @@ key of a map, and it means \"go to the value associated with this key\". "
;; Avoid throwing actual errors, since this happens on every breakpoint.
(error (message "Can't find instrumented sexp, did you edit the source?"))))

(defun cider--debug-position-for-code (code)
"Return non-nil if point is roughly before CODE.
This might move point one line above."
(or (looking-at-p (regexp-quote code))
(let ((trimmed (regexp-quote (cider--debug-trim-code code))))
(or (looking-at-p trimmed)
;; If this is a fake #dbg injected by `C-u
;; C-M-x', then the sexp we want is actually on
;; the line above.
(progn (forward-line -1)
(looking-at-p trimmed))))))

(defun cider--debug-find-source-position (response &optional create-if-needed)
"Return a marker of the position after the sexp specified in RESPONSE.
This marker might be in a different buffer! If the sexp can't be
Expand Down Expand Up @@ -526,8 +538,7 @@ is a coordinate measure in sexps."
(forward-line (- line (line-number-at-pos)))
(move-to-column column)
;; Check if it worked
(when (or (looking-at-p (regexp-quote code))
(looking-at-p (regexp-quote (cider--debug-trim-code code))))
(when (cider--debug-position-for-code code)
;; Find the desired sexp.
(cider--debug-move-point coor)
(setq out (point-marker))))))
Expand Down
2 changes: 1 addition & 1 deletion cider-interaction.el
Expand Up @@ -1125,7 +1125,7 @@ command `cider-debug-defun-at-point'."
(browse-url "https://github.com/clojure-emacs/cider/issues/1416"))
(user-error "The debugger does not support ClojureScript"))
(cider-interactive-eval
(concat (if debug-it "#dbg ")
(concat (if debug-it "#dbg\n")
(cider-defun-at-point))
nil
(cider--region-for-defun-at-point)))
Expand Down

0 comments on commit 5ae5228

Please sign in to comment.