emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master daac75b 175/215: Add a C-u interface to break and clear


From: Rocky Bernstein
Subject: [elpa] master daac75b 175/215: Add a C-u interface to break and clear
Date: Sat, 30 Jul 2016 14:49:04 +0000 (UTC)

branch: master
commit daac75bb3187cdf1fe0c2e3a3ca73bfe40a3118a
Author: Clément Pit--Claudel <address@hidden>
Commit: Clément Pit--Claudel <address@hidden>

    Add a C-u interface to break and clear
    
    Prefix either command with C-u now  prompts for a line number in the
    current file, which prefixing with a numeric argument acts on that line.
---
 realgud/common/cmds.el |   60 +++++++++++++++++++++++++++++++++++++++---------
 realgud/common/send.el |    8 +++++++
 2 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/realgud/common/cmds.el b/realgud/common/cmds.el
index 30b76cd..22a10f9 100644
--- a/realgud/common/cmds.el
+++ b/realgud/common/cmds.el
@@ -51,6 +51,39 @@ when command was run from a menu."
         t)
     t))
 
+(defun realgud:cmd--line-number-from-prefix-arg ()
+  "Guess or read a line number based on prefix arg.
+Returns (nil) for current line, and a list whose car is the line
+number otherwise."
+  (cond
+   ((numberp current-prefix-arg)
+    current-prefix-arg)
+   ((consp current-prefix-arg)
+    (let* ((min-line (save-excursion
+                       (goto-char (point-min))
+                       (line-number-at-pos)))
+           (max-line (save-excursion
+                       (goto-char (point-max))
+                       (line-number-at-pos)))
+           (prompt (format "Line number (%d..%d)? " min-line max-line))
+           (picked-line 0))
+      (while (not (<= min-line picked-line max-line))
+        (setq picked-line (read-number prompt)))
+      (list picked-line)))))
+
+(defmacro realgud:cmd--with-line-override (line &rest body)
+  "Run BODY with %l format specifier bound to LINE.
+This is needed because going to LINE explicitly would interfere
+with other motion initiated by debugger messages."
+  (declare (indent 1)
+           (debug t))
+  (let ((line-var (make-symbol "--line--")))
+    `(let* ((,line-var ,line)
+            (realgud-expand-format-overrides
+             (cons (cons ?l (and ,line-var (number-to-string ,line-var)))
+                   realgud-expand-format-overrides)))
+       ,@body)))
+
 (defconst realgud-cmd:default-hash
   (let ((hash (make-hash-table :test 'equal)))
     (puthash "backtrace" "backtrace" hash)
@@ -122,8 +155,8 @@ ARG, CMD-NAME, DEFAULT-CMD-TEMPLATE are as in 
`realgud:cmd-run-command'.
 KEY is ignored.  NO-RECORD?, FRAME-SWITCH?, REALGUD-PROMPTS? are
 as in `realgud:cmd-run-command'."
   (realgud:cmd-run-command arg cmd-name default-cmd-template
-                   no-record? frame-switch?
-                   realgud-prompts?))
+                           no-record? frame-switch?
+                           realgud-prompts?))
 
 (make-obsolete 'realgud:cmd-remap 'realgud:cmd-run-command "1.3.1")
 
@@ -133,15 +166,20 @@ as in `realgud:cmd-run-command'."
   (realgud:cmd-run-command arg "backtrace")
   )
 
-(defun realgud:cmd-break(arg)
-  "Set a breakpoint at the current line"
-  (interactive "p")
-  (realgud:cmd-run-command arg "break"))
+(defun realgud:cmd-break (&optional line-number)
+  "Set a breakpoint at the current line.
+With prefix argument LINE-NUMBER, prompt for line number."
+  (interactive (realgud:cmd--line-number-from-prefix-arg))
+  (realgud:cmd--with-line-override line-number
+                                   (realgud:cmd-run-command line-number 
"break")))
+
+(defun realgud:cmd-clear(&optional line-number)
+  "Delete breakpoint at the current line.
+With prefix argument LINE-NUMBER, prompt for line number."
+  (interactive (realgud:cmd--line-number-from-prefix-arg))
+  (realgud:cmd--with-line-override line-number
+                                   (realgud:cmd-run-command line-number 
"clear")))
 
-(defun realgud:cmd-clear(line-num)
-  "Delete breakpoint at the current line"
-  (interactive "p")
-  (realgud:cmd-run-command line-num "clear"))
 
 (defun realgud:cmd-continue(&optional arg)
     "Continue execution.
@@ -207,7 +245,7 @@ be found on the current line, prompt for a breakpoint 
number."
     (let ((existing-bp-num (realgud:bpnum-on-current-line)))
       (if existing-bp-num
           (realgud:cmd-delete existing-bp-num)
-        (realgud:cmd-break pos)))))
+        (realgud:cmd-break)))))
 
 (defun realgud-cmds--mouse-add-remove-bp (event)
   "Add or delete breakpoint on line pointed to by EVENT.
diff --git a/realgud/common/send.el b/realgud/common/send.el
index 648632b..c068c4f 100644
--- a/realgud/common/send.el
+++ b/realgud/common/send.el
@@ -116,6 +116,13 @@ results into the command buffer."
 (defun realgud-send-command-invisible (command-str)
   (realgud-send-command command-str (function realgud-send-command-process)))
 
+(defvar realgud-expand-format-overrides nil
+  "An alist of overrides for `realgud-expand-format'.
+Each element should have the form (KEY . VALUE).  Key should be a
+single-character escape accepted by `realgud-expand-format';
+value should be a string.  Every time %KEY is encountered in te
+string, it will be replaced by VALUE instead of being processed
+as usual.  If VALUE is nil, the override is ignored.")
 
 (defun realgud-expand-format (fmt-str &optional opt-str opt-buffer)
   "Expands commands format characters inside FMT-STR.
@@ -148,6 +155,7 @@ taken from current buffer, or OPT-BUFFER if non-nil.  Some
              (concat
               result (match-string 1 fmt-str)
               (cond
+               ((cdr (assq key realgud-expand-format-overrides)))
                ((eq key ?d)
                 (or (and src-file-name
                          (file-name-directory src-file-name))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]