diff options
| author | Po Lu | 2023-10-12 21:46:54 +0800 |
|---|---|---|
| committer | Po Lu | 2023-10-12 21:46:54 +0800 |
| commit | c6f07e13eef93af8b25064bb1bc975e8fafad591 (patch) | |
| tree | 1c7ee68d335ee3072d5a2feb4140046dfb48d02d | |
| parent | 088dd67f891553e1a27e65c97e386d0dd8dc4f64 (diff) | |
| download | emacs-c6f07e13eef93af8b25064bb1bc975e8fafad591.tar.gz emacs-c6f07e13eef93af8b25064bb1bc975e8fafad591.zip | |
Enable highlighting Gud execution lines without hl-line-mode
* doc/emacs/building.texi (Debugger Operation): Mention two new
options and the relationship between Gud and HL Line Mode.
* etc/NEWS (Editing Changes in Emacs 30.1): Mention the new
option.
* lisp/progmodes/gud.el (gud-highlight-current-line-overlay):
New variable.
(gud-sentinel) <signal, exit>: Delete that overlay if set.
(gud-highlight-current-line, gud-highlight-current-line-face):
New user options.
(gud-display-line): Create and move an overlay without employing
hl-line-mode, if so enjoined by the user.
| -rw-r--r-- | doc/emacs/building.texi | 14 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/progmodes/gud.el | 60 |
3 files changed, 72 insertions, 8 deletions
diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index d6610099460..2a98bffdc2d 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi | |||
| @@ -698,6 +698,20 @@ which edited source line corresponds to the line reported by the | |||
| 698 | debugger subprocess. To update this information, you typically have | 698 | debugger subprocess. To update this information, you typically have |
| 699 | to recompile and restart the program. | 699 | to recompile and restart the program. |
| 700 | 700 | ||
| 701 | @cindex GUD and hl-line-mode | ||
| 702 | @cindex highlighting execution lines in GUD | ||
| 703 | @vindex gud-highlight-current-line | ||
| 704 | Moreover, GUD is capable of visually demarcating the current | ||
| 705 | execution line within the window text itself in one of two fashions: | ||
| 706 | the first takes effect when the user option | ||
| 707 | @code{gud-highlight-current-line} is enabled, and displays that line | ||
| 708 | in an overlay whose appearance is provided by the face | ||
| 709 | @code{gud-highlight-current-line-face}. The other takes effect when | ||
| 710 | HL Line Mode (@pxref{Cursor Display}) is enabled, and moves the | ||
| 711 | overlay introduced by HL Line Mode briefly to the execution line, | ||
| 712 | until a subsequent editing command repositions it back beneath the | ||
| 713 | cursor. | ||
| 714 | |||
| 701 | @cindex GUD Tooltip mode | 715 | @cindex GUD Tooltip mode |
| 702 | @cindex mode, GUD Tooltip | 716 | @cindex mode, GUD Tooltip |
| 703 | @findex gud-tooltip-mode | 717 | @findex gud-tooltip-mode |
| @@ -197,6 +197,12 @@ displayed on the mode line when 'appt-display-mode-line' is non-nil. | |||
| 197 | 197 | ||
| 198 | * Editing Changes in Emacs 30.1 | 198 | * Editing Changes in Emacs 30.1 |
| 199 | 199 | ||
| 200 | +++ | ||
| 201 | ** New user option 'gud-highlight-current-line-overlay'. | ||
| 202 | When enabled, Gud will visually emphasize the line being executed upon | ||
| 203 | pauses in the debugee's execution, such as those occasioned by | ||
| 204 | breakpoints being hit. | ||
| 205 | |||
| 200 | --- | 206 | --- |
| 201 | ** New global minor mode 'kill-ring-deindent-mode'. | 207 | ** New global minor mode 'kill-ring-deindent-mode'. |
| 202 | When enabled, text being saved to the kill ring will be de-indented by | 208 | When enabled, text being saved to the kill ring will be de-indented by |
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el index 3cc63aab84f..d4b954a7203 100644 --- a/lisp/progmodes/gud.el +++ b/lisp/progmodes/gud.el | |||
| @@ -2942,6 +2942,10 @@ It is saved for when this flag is not set.") | |||
| 2942 | (declare-function speedbar-change-initial-expansion-list "speedbar" (new)) | 2942 | (declare-function speedbar-change-initial-expansion-list "speedbar" (new)) |
| 2943 | (defvar speedbar-previously-used-expansion-list-name) | 2943 | (defvar speedbar-previously-used-expansion-list-name) |
| 2944 | 2944 | ||
| 2945 | (defvar gud-highlight-current-line-overlay nil | ||
| 2946 | "Overlay created for `gud-highlight-current-line'. | ||
| 2947 | It is nil if not yet present.") | ||
| 2948 | |||
| 2945 | (defun gud-sentinel (proc msg) | 2949 | (defun gud-sentinel (proc msg) |
| 2946 | (cond ((null (buffer-name (process-buffer proc))) | 2950 | (cond ((null (buffer-name (process-buffer proc))) |
| 2947 | ;; buffer killed | 2951 | ;; buffer killed |
| @@ -2958,6 +2962,10 @@ It is saved for when this flag is not set.") | |||
| 2958 | ((memq (process-status proc) '(signal exit)) | 2962 | ((memq (process-status proc) '(signal exit)) |
| 2959 | ;; Stop displaying an arrow in a source file. | 2963 | ;; Stop displaying an arrow in a source file. |
| 2960 | (setq gud-overlay-arrow-position nil) | 2964 | (setq gud-overlay-arrow-position nil) |
| 2965 | ;; And any highlight overlays. | ||
| 2966 | (when gud-highlight-current-line-overlay | ||
| 2967 | (delete-overlay gud-highlight-current-line-overlay) | ||
| 2968 | (setq gud-highlight-current-line-overlay nil)) | ||
| 2961 | (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) | 2969 | (if (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer) |
| 2962 | 'gdbmi) | 2970 | 'gdbmi) |
| 2963 | (gdb-reset) | 2971 | (gdb-reset) |
| @@ -3024,6 +3032,24 @@ Obeying it means displaying in another window the specified file and line." | |||
| 3024 | ;; region-restriction if that's possible. We use an explicit display-buffer | 3032 | ;; region-restriction if that's possible. We use an explicit display-buffer |
| 3025 | ;; to get around the fact that this is called inside a save-excursion. | 3033 | ;; to get around the fact that this is called inside a save-excursion. |
| 3026 | 3034 | ||
| 3035 | (defcustom gud-highlight-current-line nil | ||
| 3036 | "Whether Gud should highlight the source line being debugged. | ||
| 3037 | If non-nil, Gud will accentuate the source code line previously | ||
| 3038 | executed upon each pause in the debugee's execution with an | ||
| 3039 | overlay in the face `gud-highlight-current-line-face'. | ||
| 3040 | |||
| 3041 | If nil, yet one of `hl-line-mode' or `global-hl-line-mode' (which | ||
| 3042 | see) is enabled, then the emphasis imposed by either of those | ||
| 3043 | major modes is instead momentarily moved to the aforesaid source | ||
| 3044 | line, until it is displaced by subsequent cursor motion." | ||
| 3045 | :version "30.1" | ||
| 3046 | :type 'boolean) | ||
| 3047 | |||
| 3048 | (defface gud-highlight-current-line-face | ||
| 3049 | '((t :inherit highlight :extend t)) | ||
| 3050 | "Face for highlighting the source code line being executed." | ||
| 3051 | :version "30.1") | ||
| 3052 | |||
| 3027 | (defun gud-display-line (true-file line) | 3053 | (defun gud-display-line (true-file line) |
| 3028 | (let* ((last-nonmenu-event t) ; Prevent use of dialog box for questions. | 3054 | (let* ((last-nonmenu-event t) ; Prevent use of dialog box for questions. |
| 3029 | (buffer | 3055 | (buffer |
| @@ -3053,14 +3079,32 @@ Obeying it means displaying in another window the specified file and line." | |||
| 3053 | (or gud-overlay-arrow-position | 3079 | (or gud-overlay-arrow-position |
| 3054 | (setq gud-overlay-arrow-position (make-marker))) | 3080 | (setq gud-overlay-arrow-position (make-marker))) |
| 3055 | (set-marker gud-overlay-arrow-position (point) (current-buffer)) | 3081 | (set-marker gud-overlay-arrow-position (point) (current-buffer)) |
| 3056 | ;; If they turned on hl-line, move the hl-line highlight to | 3082 | (if gud-highlight-current-line |
| 3057 | ;; the arrow's line. | 3083 | (progn |
| 3058 | (when (featurep 'hl-line) | 3084 | (unless gud-highlight-current-line-overlay |
| 3059 | (cond | 3085 | ;; Create the highlight overlay if it does not yet |
| 3060 | (global-hl-line-mode | 3086 | ;; exist. |
| 3061 | (global-hl-line-highlight)) | 3087 | (let ((overlay (make-overlay (point) (point)))) |
| 3062 | ((and hl-line-mode hl-line-sticky-flag) | 3088 | (overlay-put overlay 'priority -45) ; 5 less than hl-line. |
| 3063 | (hl-line-highlight))))) | 3089 | (overlay-put overlay 'face 'gud-highlight-current-line-face) |
| 3090 | (setq gud-highlight-current-line-overlay overlay))) | ||
| 3091 | ;; Next, move the overlay to the current line. | ||
| 3092 | (move-overlay gud-highlight-current-line-overlay | ||
| 3093 | (line-beginning-position) | ||
| 3094 | (line-beginning-position 2) | ||
| 3095 | (current-buffer))) | ||
| 3096 | ;; Delete any overlay introduced if g-h-c-l-f has changed. | ||
| 3097 | (when gud-highlight-current-line-overlay | ||
| 3098 | (delete-overlay gud-highlight-current-line-overlay) | ||
| 3099 | (setq gud-highlight-current-line-overlay nil)) | ||
| 3100 | ;; If they turned on hl-line, move the hl-line highlight to | ||
| 3101 | ;; the arrow's line. | ||
| 3102 | (when (featurep 'hl-line) | ||
| 3103 | (cond | ||
| 3104 | (global-hl-line-mode | ||
| 3105 | (global-hl-line-highlight)) | ||
| 3106 | ((and hl-line-mode hl-line-sticky-flag) | ||
| 3107 | (hl-line-highlight)))))) | ||
| 3064 | (cond ((or (< pos (point-min)) (> pos (point-max))) | 3108 | (cond ((or (< pos (point-min)) (> pos (point-max))) |
| 3065 | (widen) | 3109 | (widen) |
| 3066 | (goto-char pos)))) | 3110 | (goto-char pos)))) |