emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r108362: * lisp/progmodes/gdb-mi.el:


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108362: * lisp/progmodes/gdb-mi.el: Minor style changes.
Date: Fri, 25 May 2012 10:47:57 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108362
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2012-05-25 10:47:57 -0400
message:
  * lisp/progmodes/gdb-mi.el: Minor style changes.
  (gdb-enable-debug, gdb-speedbar-auto-raise, gdb-many-windows):
  Turn into minor modes.
  (gdb--if-arrow): Rename from gdb-if-arrow, make it hygienic.
  (gdb-mouse-until, gdb-mouse-jump): Adjust uses accordingly.
  (gdb-shell): Remove unneeded let-binding.
  (gdb-get-many-fields): Eliminate O(n²) behavior.
modified:
  lisp/ChangeLog
  lisp/progmodes/gdb-mi.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-05-25 10:31:18 +0000
+++ b/lisp/ChangeLog    2012-05-25 14:47:57 +0000
@@ -1,3 +1,13 @@
+2012-05-25  Stefan Monnier  <address@hidden>
+
+       * progmodes/gdb-mi.el: Minor style changes.
+       (gdb-enable-debug, gdb-speedbar-auto-raise, gdb-many-windows):
+       Turn into minor modes.
+       (gdb--if-arrow): Rename from gdb-if-arrow, make it hygienic.
+       (gdb-mouse-until, gdb-mouse-jump): Adjust uses accordingly.
+       (gdb-shell): Remove unneeded let-binding.
+       (gdb-get-many-fields): Eliminate O(n²) behavior.
+
 2012-05-25  Eli Zaretskii  <address@hidden>
 
        * cus-start.el <vertical-centering-font-regexp>: Avoid warning on

=== modified file 'lisp/progmodes/gdb-mi.el'
--- a/lisp/progmodes/gdb-mi.el  2012-04-27 03:10:38 +0000
+++ b/lisp/progmodes/gdb-mi.el  2012-05-25 14:47:57 +0000
@@ -459,9 +459,14 @@
 `gdb-debug-log-max' values.  This variable is used to debug GDB-MI.")
 
 ;;;###autoload
-(defcustom gdb-enable-debug nil
-  "Non-nil means record the process input and output in `gdb-debug-log'."
-  :type 'boolean
+(define-minor-mode gdb-enable-debug
+  "Toggle logging of transaction between Emacs and Gdb.
+The log is stored in `gdb-debug-log' as an alist with elements
+whose cons is send, send-item or recv and whose cdr is the string
+being transferred.  This list may grow up to a size of
+`gdb-debug-log-max' after which the oldest element (at the end of
+the list) is deleted every time a new one is added (at the front)."
+  :global t
   :group 'gdb
   :version "22.1")
 
@@ -512,21 +517,6 @@
          ;; Force mode line redisplay soon.
          (force-mode-line-update)))))
 
-(defun gdb-enable-debug (arg)
-  "Toggle logging of transaction between Emacs and Gdb.
-The log is stored in `gdb-debug-log' as an alist with elements
-whose cons is send, send-item or recv and whose cdr is the string
-being transferred.  This list may grow up to a size of
-`gdb-debug-log-max' after which the oldest element (at the end of
-the list) is deleted every time a new one is added (at the front)."
-  (interactive "P")
-  (setq gdb-enable-debug
-       (if (null arg)
-           (not gdb-enable-debug)
-         (> (prefix-numeric-value arg) 0)))
-  (message (format "Logging of transaction %sabled"
-                  (if gdb-enable-debug "en" "dis"))))
-
 ;; These two are used for menu and toolbar
 (defun gdb-control-all-threads ()
   "Switch to non-stop/A mode."
@@ -830,7 +820,7 @@
   (run-hooks 'gdb-mode-hook))
 
 (defun gdb-init-1 ()
-  ;; (re-)initialize
+  ;; (Re-)initialize.
   (setq gdb-selected-frame nil
        gdb-frame-number nil
         gdb-thread-number nil
@@ -879,7 +869,7 @@
 
   (gdb-input "-enable-pretty-printing" 'ignore)
 
-  ;; find source file and compilation directory here
+  ;; Find source file and compilation directory here.
   (if gdb-create-source-file-list
       ;; Needs GDB 6.2 onwards.
       (gdb-input "-file-list-exec-source-files" 'gdb-get-source-file-list))
@@ -979,15 +969,17 @@
     (gdb-create-define-alist)
     (add-hook 'after-save-hook 'gdb-create-define-alist nil t)))
 
-(defmacro gdb-if-arrow (arrow-position &rest body)
-  `(if ,arrow-position
-       (let ((buffer (marker-buffer ,arrow-position)) (line))
-         (if (equal buffer (window-buffer (posn-window end)))
-             (with-current-buffer buffer
-               (when (or (equal start end)
-                         (equal (posn-point start)
-                                (marker-position ,arrow-position)))
-                 ,@body))))))
+(defmacro gdb--if-arrow (arrow-position start-posn end-posn &rest body)
+  (declare (indent 3))
+  (let ((buffer (make-symbol "buffer")))
+    `(if ,arrow-position
+         (let ((,buffer (marker-buffer ,arrow-position)))
+           (if (equal ,buffer (window-buffer (posn-window ,end-posn)))
+               (with-current-buffer ,buffer
+                 (when (or (equal ,start-posn ,end-posn)
+                           (equal (posn-point ,start-posn)
+                                  (marker-position ,arrow-position)))
+                   ,@body)))))))
 
 (defun gdb-mouse-until (event)
   "Continue running until a source line past the current line.
@@ -997,15 +989,15 @@
   (interactive "e")
   (let ((start (event-start event))
        (end (event-end event)))
-    (gdb-if-arrow gud-overlay-arrow-position
-                 (setq line (line-number-at-pos (posn-point end)))
-                 (gud-call (concat "until " (number-to-string line))))
-    (gdb-if-arrow gdb-disassembly-position
-                 (save-excursion
-                   (goto-char (point-min))
-                   (forward-line (1- (line-number-at-pos (posn-point end))))
-                   (forward-char 2)
-                   (gud-call (concat "until *%a"))))))
+    (gdb--if-arrow gud-overlay-arrow-position start end
+      (let ((line (line-number-at-pos (posn-point end))))
+        (gud-call (concat "until " (number-to-string line)))))
+    (gdb--if-arrow gdb-disassembly-position start end
+      (save-excursion
+        (goto-char (point-min))
+        (forward-line (1- (line-number-at-pos (posn-point end))))
+        (forward-char 2)
+        (gud-call (concat "until *%a"))))))
 
 (defun gdb-mouse-jump (event)
   "Set execution address/line.
@@ -1016,19 +1008,17 @@
   (interactive "e")
   (let ((start (event-start event))
        (end (event-end event)))
-    (gdb-if-arrow gud-overlay-arrow-position
-                 (setq line (line-number-at-pos (posn-point end)))
-                 (progn
-                   (gud-call (concat "tbreak " (number-to-string line)))
-                   (gud-call (concat "jump " (number-to-string line)))))
-    (gdb-if-arrow gdb-disassembly-position
-                 (save-excursion
-                   (goto-char (point-min))
-                   (forward-line (1- (line-number-at-pos (posn-point end))))
-                   (forward-char 2)
-                   (progn
-                     (gud-call (concat "tbreak *%a"))
-                     (gud-call (concat "jump *%a")))))))
+    (gdb--if-arrow gud-overlay-arrow-position start end
+      (let ((line (line-number-at-pos (posn-point end))))
+        (gud-call (concat "tbreak " (number-to-string line)))
+        (gud-call (concat "jump " (number-to-string line)))))
+    (gdb--if-arrow gdb-disassembly-position start end
+      (save-excursion
+        (goto-char (point-min))
+        (forward-line (1- (line-number-at-pos (posn-point end))))
+        (forward-char 2)
+        (gud-call (concat "tbreak *%a"))
+        (gud-call (concat "jump *%a"))))))
 
 (defcustom gdb-show-changed-values t
   "If non-nil change the face of out of scope variables and changed values.
@@ -1050,10 +1040,11 @@
   :group 'gdb
   :version "22.2")
 
-(defcustom gdb-speedbar-auto-raise nil
-  "If non-nil raise speedbar every time display of watch expressions is\
- updated."
-  :type 'boolean
+(define-minor-mode gdb-speedbar-auto-raise
+  "Minor mode to automatically raise the speedbar for watch expressions.
+With prefix argument ARG, automatically raise speedbar if ARG is
+positive, otherwise don't automatically raise it."
+  :global t
   :group 'gdb
   :version "22.1")
 
@@ -1063,18 +1054,6 @@
   :group 'gdb
   :version "22.1")
 
-(defun gdb-speedbar-auto-raise (arg)
-  "Toggle automatic raising of the speedbar for watch expressions.
-With prefix argument ARG, automatically raise speedbar if ARG is
-positive, otherwise don't automatically raise it."
-  (interactive "P")
-  (setq gdb-speedbar-auto-raise
-       (if (null arg)
-           (not gdb-speedbar-auto-raise)
-         (> (prefix-numeric-value arg) 0)))
-  (message (format "Auto raising %sabled"
-                  (if gdb-speedbar-auto-raise "en" "dis"))))
-
 (define-key gud-minor-mode-map "\C-c\C-w" 'gud-watch)
 (define-key global-map (vconcat gud-key-prefix "\C-w") 'gud-watch)
 
@@ -1212,8 +1191,8 @@
 (defun gdb-edit-value (_text _token _indent)
   "Assign a value to a variable displayed in the speedbar."
   (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
-        (varnum (car var)) (value))
-    (setq value (read-string "New value: "))
+        (varnum (car var))
+         (value (read-string "New value: ")))
     (gdb-input (concat "-var-assign " varnum " " value)
               `(lambda () (gdb-edit-value-handler ,value)))))
 
@@ -1865,7 +1844,7 @@
     (setq gud-running
           (string= (bindat-get-field (gdb-current-buffer-thread) 'state)
                    "running"))
-    ;; Set frame number to "0" when _current_ threads stops
+    ;; Set frame number to "0" when _current_ threads stops.
     (when (and (gdb-current-buffer-thread)
                (not (eq gud-running old-value)))
       (setq gdb-frame-number "0"))))
@@ -1933,10 +1912,10 @@
             (> (length gdb-debug-log) gdb-debug-log-max))
        (setcdr (nthcdr (1- gdb-debug-log-max) gdb-debug-log) nil)))
 
-  ;; Recall the left over gud-marker-acc from last time
+  ;; Recall the left over gud-marker-acc from last time.
   (setq gud-marker-acc (concat gud-marker-acc string))
 
-  ;; Start accumulating output for the GUD buffer
+  ;; Start accumulating output for the GUD buffer.
   (setq gdb-filter-output "")
   (let (output-record-list)
 
@@ -1982,9 +1961,8 @@
 (defun gdb-gdb (_output-field))
 
 (defun gdb-shell (output-field)
-  (let ((gdb-output-sink gdb-output-sink))
-    (setq gdb-filter-output
-          (concat output-field gdb-filter-output))))
+  (setq gdb-filter-output
+        (concat output-field gdb-filter-output)))
 
 (defun gdb-ignored-notification (_output-field))
 
@@ -2068,14 +2046,15 @@
                             (concat " --thread " thread-id)))
                 'gdb-register-names-handler))
 
-;;; Don't set gud-last-frame here as it's currently done in gdb-frame-handler
-;;; because synchronous GDB doesn't give these fields with CLI.
-;;;     (when file
-;;;       (setq
-;;;        ;; Extract the frame position from the marker.
-;;;        gud-last-frame (cons file
-;;;                        (string-to-number
-;;;                         (match-string 6 gud-marker-acc)))))
+    ;; Don't set gud-last-frame here as it's currently done in
+    ;; gdb-frame-handler because synchronous GDB doesn't give these fields
+    ;; with CLI.
+    ;;(when file
+    ;;  (setq
+    ;;   ;; Extract the frame position from the marker.
+    ;;   gud-last-frame (cons file
+    ;;                     (string-to-number
+    ;;                      (match-string 6 gud-marker-acc)))))
 
     (setq gdb-inferior-status (or reason "unknown"))
     (gdb-force-mode-line-update
@@ -2359,8 +2338,9 @@
 (defun gdb-get-many-fields (struct &rest fields)
   "Return a list of FIELDS values from STRUCT."
   (let ((values))
-    (dolist (field fields values)
-      (setq values (append values (list (bindat-get-field struct field)))))))
+    (dolist (field fields)
+      (push (bindat-get-field struct field) values))
+    (nreverse values)))
 
 (defmacro def-gdb-auto-update-trigger (trigger-name gdb-command
                                                     handler-name
@@ -4134,31 +4114,19 @@
                              nil win5))
     (select-window win0)))
 
-(defcustom gdb-many-windows nil
+(define-minor-mode gdb-many-windows
   "If nil just pop up the GUD buffer unless `gdb-show-main' is t.
 In this case it starts with two windows: one displaying the GUD
 buffer and the other with the source file with the main routine
 of the debugged program.  Non-nil means display the layout shown for
 `gdb'."
-  :type 'boolean
+  :global t
   :group 'gdb
-  :version "22.1")
-
-(defun gdb-many-windows (arg)
-  "Toggle the number of windows in the basic arrangement.
-With arg, display additional buffers iff arg is positive."
-  (interactive "P")
-  (setq gdb-many-windows
-        (if (null arg)
-            (not gdb-many-windows)
-          (> (prefix-numeric-value arg) 0)))
-  (message (format "Display of other windows %sabled"
-                   (if gdb-many-windows "en" "dis")))
+  :version "22.1"
   (if (and gud-comint-buffer
            (buffer-name gud-comint-buffer))
-      (condition-case nil
-          (gdb-restore-windows)
-        (error nil))))
+      (ignore-errors
+        (gdb-restore-windows))))
 
 (defun gdb-restore-windows ()
   "Restore the basic arrangement of windows used by gdb.


reply via email to

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