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

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

[elpa] master 2f30f42 176/215: Merge pull request #119 from realgud/impr


From: Rocky Bernstein
Subject: [elpa] master 2f30f42 176/215: Merge pull request #119 from realgud/improve-break-C-u
Date: Sat, 30 Jul 2016 14:49:04 +0000 (UTC)

branch: master
commit 2f30f4295e7ae376005aebb55c7d4a01b7620a98
Merge: 51cd14b daac75b
Author: R. Bernstein <address@hidden>
Commit: R. Bernstein <address@hidden>

    Merge pull request #119 from realgud/improve-break-C-u
    
    Further cleanups of cmds.el + improved C-u behaviour
---
 realgud/common/cmds.el |  106 ++++++++++++++++++++++++++++++++----------------
 realgud/common/send.el |    8 ++++
 2 files changed, 78 insertions(+), 36 deletions(-)

diff --git a/realgud/common/cmds.el b/realgud/common/cmds.el
index 38cb0fc..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,26 +155,31 @@ 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")
 
 (defun realgud:cmd-backtrace(arg)
-  "Show the current call stack"
+  "Show the current call stack."
   (interactive "p")
   (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.
@@ -254,11 +292,10 @@ If no argument specified use 0 or the most recent frame."
     (realgud:cmd-run-command arg "frame" nil t t)
 )
 
-(defun realgud:cmd-kill(arg)
-  "kill debugger process"
-  (interactive "p")
-  (realgud:cmd-run-command arg "kill" nil nil nil t)
-  )
+(defun realgud:cmd-kill()
+  "Kill debugger process."
+  (interactive)
+  (realgud:cmd-run-command nil "kill" nil nil nil t))
 
 (defun realgud:cmd-newer-frame(&optional arg)
     "Move the current frame to a newer (more recent) frame.
@@ -280,8 +317,8 @@ what is getting stepped."
     (interactive "p")
     (realgud:cmd-run-command count "next"))
 
-(defun realgud:cmd-next-no-arg(&optional arg)
-    "Step one source line at current call level.
+(defun realgud:cmd-next-no-arg()
+  "Step one source line at current call level.
 
 The definition of 'next' is debugger specific so, see the
 debugger documentation for a more complete definition of what is
@@ -296,23 +333,20 @@ With a numeric argument move that many levels back."
     (realgud:cmd-run-command arg "up" nil t t)
 )
 
-(defun realgud:cmd-repeat-last(&optional arg)
-    "Repeat the last command (or generally what <enter> does."
-    (interactive "")
-    (realgud:cmd-run-command arg "repeat-last" nil t nil t)
-)
+(defun realgud:cmd-repeat-last()
+  "Repeat the last command (or generally what <enter> does."
+  (interactive)
+  (realgud:cmd-run-command nil "repeat-last" nil t nil t))
 
-(defun realgud:cmd-restart(&optional arg)
-    "Restart execution."
-    (interactive "")
-    (realgud:cmd-run-command arg "restart" nil t nil t)
-)
+(defun realgud:cmd-restart()
+  "Restart execution."
+  (interactive)
+  (realgud:cmd-run-command nil "restart" nil t nil t))
 
-(defun realgud:cmd-shell(&optional arg)
-    "Drop to a shell."
-    (interactive "")
-    (realgud:cmd-run-command arg "shell")
-)
+(defun realgud:cmd-shell()
+  "Drop to a shell."
+  (interactive)
+  (realgud:cmd-run-command nil "shell"))
 
 (defun realgud:cmd-step(&optional count)
     "Step one source line.
@@ -372,10 +406,10 @@ continuing execution."
            (unless (and cmd-hash (setq cmd (gethash "quit" cmd-hash)))
              (setq cmd "quit"))
            )
-         (realgud-command cmd arg 't)
+          (realgud-command cmd arg t)
          (if cmdbuf (realgud:terminate cmdbuf))
          )
-      ; else
+      ;; else
       (realgud:terminate-srcbuf buffer)
       )
     )
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]