branch: externals/realgud
commit b754fb93a0236d3fe5283ff835bc7cc77939fee5
Author: rocky <[email protected]>
Commit: rocky <[email protected]>

    Improve column handling
---
 realgud/common/buffer/backtrace.el  |  6 ++--
 realgud/common/buffer/breakpoint.el |  6 ++--
 realgud/common/buffer/command.el    |  1 +
 realgud/common/file.el              | 16 +++++----
 realgud/common/loc.el               | 12 +++----
 realgud/common/regexp.el            |  2 +-
 realgud/common/track.el             | 65 +++++++++++++++++++++++++------------
 realgud/lang/python.el              |  2 +-
 test/test-file.el                   |  2 +-
 test/test-lang.el                   |  3 +-
 10 files changed, 71 insertions(+), 44 deletions(-)

diff --git a/realgud/common/buffer/backtrace.el 
b/realgud/common/buffer/backtrace.el
index 4a257d9fbb..73c958a264 100644
--- a/realgud/common/buffer/backtrace.el
+++ b/realgud/common/buffer/backtrace.el
@@ -324,7 +324,7 @@ non-digit will start entry number from the beginning again."
 
 (defun realgud-goto-frame ()
   "Go to the frame number. We get the frame number from the
-'frame-num property"
+frame-num property"
   (interactive)
   (if (realgud-backtrace?)
       (let ((frame-num (get-text-property (point) 'frame-num)))
@@ -376,10 +376,10 @@ non-digit will start entry number from the beginning 
again."
 (defun realgud-goto-frame-n ()
   "Go to the frame number indicated by the accumulated numeric keys just 
entered.
 
-This function is usually bound to a numeric key in a 'frame'
+This function is usually bound to a numeric key in a frame
 secondary buffer. To go to an entry above 9, just keep entering
 the number. For example, if you press 1 and then 9, frame 1 is selected
-\(if it exists) and then frame 19 (if that exists). Entering any
+(if it exists) and then frame 19 (if that exists). Entering any
 non-digit will start entry number from the beginning again."
   (interactive)
   (if (not (eq last-command 'realgud-goto-frame-n))
diff --git a/realgud/common/buffer/breakpoint.el 
b/realgud/common/buffer/breakpoint.el
index 9eafa2b8de..a5e3c1bffa 100644
--- a/realgud/common/buffer/breakpoint.el
+++ b/realgud/common/buffer/breakpoint.el
@@ -198,7 +198,7 @@ non-digit will start entry number from the beginning again."
 
 (defun realgud-goto-breakpoint ()
   "Go to the breakpoint number. We get the breakpoint number from the
-'brkpt-num property"
+brkpt-num property"
   (interactive)
   (if (realgud-breakpoint?)
       (let ((loc (get-text-property (point) 'loc)))
@@ -226,10 +226,10 @@ non-digit will start entry number from the beginning 
again."
 (defun realgud-goto-breakpoint-n ()
   "Goto breakpoint number indicated by the accumulated numeric keys just 
entered.
 
-This function is usually bound to a numeric key in a 'frame'
+This function is usually bound to a numeric key in a frame
 secondary buffer. To go to an entry above 9, just keep entering
 the number. For example, if you press 1 and then 9, frame 1 is selected
-\(if it exists) and then frame 19 (if that exists). Entering any
+(if it exists) and then frame 19 (if that exists). Entering any
 non-digit will start entry number from the beginning again."
   (interactive)
   (if (not (eq last-command 'realgud-goto-breakpoint-n))
diff --git a/realgud/common/buffer/command.el b/realgud/common/buffer/command.el
index 767cd69382..239f64d616 100644
--- a/realgud/common/buffer/command.el
+++ b/realgud/common/buffer/command.el
@@ -471,6 +471,7 @@ values set in the debugger's init.el."
             :loc-regexp (realgud-sget 'loc-pat 'regexp)
             :file-group (realgud-sget 'loc-pat 'file-group)
             :line-group (realgud-sget 'loc-pat 'line-group)
+            :column-group (realgud-sget 'loc-pat 'column-group)
             :alt-file-group (realgud-sget 'loc-pat 'alt-file-group)
             :alt-line-group (realgud-sget 'loc-pat 'alt-line-group)
             :text-group (realgud-sget 'loc-pat 'text-group)
diff --git a/realgud/common/file.el b/realgud/common/file.el
index d0416cf9bf..e5f2766d41 100644
--- a/realgud/common/file.el
+++ b/realgud/common/file.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2010-2011, 2013-2014, 2016-2020 Free Software Foundation, Inc
+;; Copyright (C) 2010-2011, 2013-2014, 2016-2020, 2026 Free Software 
Foundation, Inc
 
 ;; Author: Rocky Bernstein <[email protected]>
 
@@ -69,13 +69,13 @@ at LINE-NUMBER or nil if it is not there"
 (defun realgud:file-ignore(filename ignore-re-file-list)
   (seq-find '(lambda (file-re) (string-match file-re filename)) 
ignore-re-file-list))
 
-;; FIXME: should allow column number to be passed in.
 (defun realgud:file-loc-from-line(filename line-number
-                                          &optional cmd-marker source-text 
bp-num
+                                          &optional column-number cmd-marker 
source-text bp-num
                                           find-file-fn directory)
-  "Return a realgud-loc for FILENAME and LINE-NUMBER and the
+  "Return a realgud-loc for FILENAME, LINE-NUMBER and the
 other optional position information.
 
+COLUMN-NUMBER is the optional staring column number. 0 is the first column.
 CMD-MARKER and BP-NUM get stored in the realgud-loc
 object. FIND-FILE-FN is a function which do special things to
 transform filename so it can be found. This could include
@@ -162,10 +162,10 @@ problem as best as we can determine."
                  (let ((line-count))
                    (if (setq line-count (realgud:file-line-count filename))
                        (if (> line-count line-number)
-                           (let* ((column-number
+                           (let* ((column-number (or column-number
                                    (realgud:file-column-from-string filename
                                                                    line-number
-                                                                   
source-text))
+                                                                   
source-text)))
                                   (source-buffer (find-file-noselect filename))
                                   (source-mark))
 
@@ -176,8 +176,10 @@ problem as best as we can determine."
                              ;; doing something other than validation?
                              (with-current-buffer source-buffer
                                (goto-char (point-min))
-                               ;; FIXME also allow column number and byte 
offset
                                (forward-line (1- line-number))
+                               (if (and column-number (numberp column-number))
+                                   (forward-char column-number))
+                               ;; FIXME also allow byte offset.
                                (make-realgud-loc
                                      :num           bp-num
                                      :cmd-marker    cmd-marker
diff --git a/realgud/common/loc.el b/realgud/common/loc.el
index d42c509884..fa5359cad4 100644
--- a/realgud/common/loc.el
+++ b/realgud/common/loc.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2015-2017, 2019 Free Software Foundation, Inc
+;; Copyright (C) 2015-2017, 2019, 2026 Free Software Foundation, Inc
 
 ;; Author: Rocky Bernstein <[email protected]>
 
@@ -54,8 +54,8 @@ want to save the values that were seen/requested originally."
 (defun realgud:buffer-line-no-props()
   "Returns a string containing the line that `point' is at,
 without buffer properties."
-  (buffer-substring-no-properties (point-at-bol)
-                                 (point-at-eol)))
+  (buffer-substring-no-properties (pos-at-bol)
+                                 (pos-at-eol)))
 
 (defun realgud:loc-describe (loc)
   "Display realgud-cmdcbuf-info.
@@ -153,7 +153,7 @@ the source-code buffer, is returned. Otherwise, nil is 
returned."
   (if (realgud-loc? loc)
       (let* ((filename    (realgud-loc-filename loc))
             (line-number (realgud-loc-line-number loc))
-            (column-number (realgud-loc-column-number loc))
+            (column-number (or (realgud-loc-column-number loc) 0))
             (marker      (realgud-loc-marker loc))
             (cmd-marker  (realgud-loc-cmd-marker loc))
             (use-marker  nil)
@@ -167,11 +167,10 @@ the source-code buffer, is returned. Otherwise, nil is 
returned."
            (with-current-buffer src-buffer
              (when (and marker (marker-position marker))
                ;; A marker has been set in loc, so use that.
-               (goto-char (marker-position marker))
                (setq use-marker 't)
                (let ((current-text (realgud:buffer-line-no-props))
                      (loc-text (realgud-loc-source-text loc)))
-                 (unless (and loc-text
+                 (unless (and loc-text (eql column-number 0)
                               (equal (realgud:strip current-text) 
(realgud:strip loc-text)))
                    (loc-changes-goto line-number)
                    (setq current-text (realgud:buffer-line-no-props))
@@ -195,6 +194,7 @@ the source-code buffer, is returned. Otherwise, nil is 
returned."
                  (setq src-marker (point-marker))
                  (realgud-loc-marker= loc src-marker)
                  ))))
+
        src-buffer )))
 
 (provide-me "realgud-")
diff --git a/realgud/common/regexp.el b/realgud/common/regexp.el
index 7af082af95..e3b54850cf 100644
--- a/realgud/common/regexp.el
+++ b/realgud/common/regexp.el
@@ -42,6 +42,7 @@ output by a debugger inside a process shell"
   (regexp)             ;; a stack position, or thread number.
   (file-group)         ;; Filename position in struct
   (line-group)         ;; Line number position in struct
+  (column-group)       ;; Starting column position in struct
 
   ;; FIXME: fix code to handle lists of locs and then remove
   (alt-file-group)     ;; Used when regexp is too complicated and use \|
@@ -51,7 +52,6 @@ output by a debugger inside a process shell"
 
   (char-offset-group)  ;; Character offset position in struct
   (instruction-address-group)
-  (column-group)
   (ignore-file-re)     ;; Some debuggers create pseudo files in eval strings
                        ;; for example "(eval)" in Ruby and Perl
   (text-group)         ;; Some source text that should found at position
diff --git a/realgud/common/track.el b/realgud/common/track.el
index 6c73c9cd73..15333b49c8 100644
--- a/realgud/common/track.el
+++ b/realgud/common/track.el
@@ -1,4 +1,4 @@
-;; Copyright (C) 2015-2020, 2025 Free Software Foundation, Inc
+;; Copyright (C) 2015-2020, 2025-2026 Free Software Foundation, Inc
 
 ;; Author: Rocky Bernstein <[email protected]>
 
@@ -90,18 +90,26 @@
 (fn-p-to-fn?-alias 'realgud-loc-p)
 
 (defvar realgud-track-divert-string
-  ""
-  "Some commands need information from the debugger to perform certain 
actions, such as show what breapoints exist, give back trace information. The 
output of debugger commands which need to be captured, are stored in this 
buffer-local string variable.")
+  "Some commands need information from the debugger to perform
+  certain actions, such as show what breapoints exist, give back trace
+  information. The output of debugger commands which need to be
+  captured, are stored in this buffer-local string variable.")
 
 (defvar starting-directory
   nil
-  "When set this indicates the base directory that source code path should be 
based off of when the path is a relative path."
+  "When set this indicates the base directory that source code path
+should be based off of when the path is a relative path."
   )
 
 
 (defvar realgud-command-name-hash
   nil
-  "This buffer-local hash maps a debugger, like `gdb', or `pdb', to a hash 
table which describes how to implement generic debugger functions into the 
commands of that debugger. This information is set up by individual `init' 
function of the debugger. The keys at any given time will be those debuggers 
that have been used so far in the Emacs session.")
+  "This buffer-local hash maps a debugger, like `gdb', or `pdb', to a
+  hash table which describes how to implement generic debugger
+  functions into the commands of that debugger. This information is
+  set up by individual `init' function of the debugger. The keys at
+  any given time will be those debuggers that have been used so far in
+  the Emacs session.")
 
 (defun realgud-track-comint-output-filter-hook(text)
   "An output-filter hook custom for comint shells.  Find
@@ -382,6 +390,7 @@ encountering a new loc."
           (srcbuf-loc-hist)
           )
 
+       ;; (message "loc-action %s" loc)
        (setq srcbuf (realgud-loc-goto loc))
        (realgud-srcbuf-init-or-update srcbuf cmdbuf)
        (setq srcbuf-loc-hist (realgud-srcbuf-loc-hist srcbuf))
@@ -420,7 +429,11 @@ encountering a new loc."
                      ;;        (set-fringe-bitmap-face 'realgud-right-triangle1
                      ;;                                'realgud-overlay-arrow1)
                      ;;        )
-                     (realgud-window-update-position srcbuf 
realgud-overlay-arrow1)))
+                     (realgud-window-update-position srcbuf 
realgud-overlay-arrow1)
+                     ;; FIXME: realgud-overlay-arrow1 doesn't seem to capture 
a column number
+                     ;; so instead explicitly go to "loc".
+                     (realgud-loc-goto loc)
+                     ))
                )
              (if cmd-window (select-window cmd-window)))
          ; else
@@ -440,7 +453,7 @@ encountering a new loc."
   )
 
 (defun realgud-track-loc(text cmd-mark &optional opt-regexp opt-file-group
-                          opt-line-group no-warn-on-no-match?)
+                          opt-line-group opt-column-group no-warn-on-no-match?)
   "Do regular-expression matching to find a file name and line number inside
 string TEXT. If we match, we will turn the result into a realgud-loc struct.
 Otherwise return nil."
@@ -461,6 +474,9 @@ Otherwise return nil."
                           (realgud-sget 'cmdbuf-info 'file-group)))
           (line-group (or opt-line-group
                           (realgud-sget 'cmdbuf-info 'line-group)))
+          ;; If column-group is nil, we'll use a large number to match to nil
+          (column-group (or opt-column-group
+                          (realgud-sget 'cmdbuf-info 'column-group) 1000))
           (alt-file-group (realgud-sget 'cmdbuf-info 'alt-file-group))
           (alt-line-group (realgud-sget 'cmdbuf-info 'alt-line-group))
           (text-group (realgud-sget 'cmdbuf-info 'text-group))
@@ -472,9 +488,11 @@ Otherwise return nil."
                                     (match-string alt-file-group text)))
                       (line-str (or (match-string line-group text)
                                     (match-string alt-line-group text)))
+                      (column-str (match-string column-group text))
                       (source-str (and text-group
                                        (match-string text-group text)))
                       (lineno (string-to-number (or line-str "1")))
+                      (column (string-to-number (or column-str "0")))
                       (directory
                        (cond ((boundp 'starting-directory) starting-directory)
                                     (t nil)))
@@ -491,6 +509,7 @@ Otherwise return nil."
                           (message "line number not found -- using 1"))
                         (if (and filename lineno)
                             (realgud:file-loc-from-line filename lineno
+                                                        column
                                                         cmd-mark
                                                         source-str nil
                                                         nil
@@ -534,8 +553,8 @@ Otherwise return nil. CMD-MARK is set in the realgud-loc 
object created.
                  (loc-regexp     (realgud-loc-pat-regexp loc-pat))
                  (file-group     (realgud-loc-pat-file-group loc-pat))
                  (line-group     (realgud-loc-pat-line-group loc-pat))
-                 (text-group     (realgud-loc-pat-text-group loc-pat))
                  (column-group   (realgud-loc-pat-column-group loc-pat))
+                 (text-group     (realgud-loc-pat-text-group loc-pat))
                  (ignore-re-file-list (or opt-ignore-re-file-list
                                           (realgud-sget 'cmdbuf-info 
'ignore-re-file-list)))
                  (callback-loc-fn (realgud-sget 'cmdbuf-info 'callback-loc-fn))
@@ -552,7 +571,7 @@ Otherwise return nil. CMD-MARK is set in the realgud-loc 
object created.
                             (source-str (and text-group (match-string 
text-group text)))
                             (lineno (string-to-number (or line-str "1")))
                             (column-str (and column-group (match-string 
column-group text)))
-                            (column (string-to-number (or column-str "1")))
+                            (column (string-to-number (or column-str "0")))
                             (directory
                              (cond ((boundp 'starting-directory) 
starting-directory)
                                    (t nil)))
@@ -682,10 +701,10 @@ of the breakpoints found in command buffer."
             found-locs))))))
 
 (defun realgud-track-bp-enable-disable(text loc-pat enable? &optional cmdbuf)
-  "Do regular-expression matching see if a breakpoint has been enabled or 
disabled inside
-string TEXT. If we match, we will do the action to the breakpoint found and 
return the
-breakpoint location. Otherwise return nil.
-"
+  "Do regular-expression matching see if a breakpoint has been enabled
+or disabled inside string TEXT. If we match, we will do the action to
+the breakpoint found and return the breakpoint location. Otherwise
+return nil."
   (setq cmdbuf (or cmdbuf (current-buffer)))
   (with-current-buffer cmdbuf
     (if (realgud-cmdbuf?)
@@ -766,10 +785,12 @@ loc-regexp pattern"
            (if (string-match frame-num-regexp text)
                (let* ((file-group (realgud-loc-pat-file-group 
selected-frame-pat))
                       (line-group (realgud-loc-pat-line-group 
selected-frame-pat))
+                      (column-group (realgud-loc-pat-column-group 
selected-frame-pat))
                       (filename (match-string file-group text))
-                      (lineno (string-to-number (match-string line-group 
text))))
+                      (lineno (string-to-number (match-string line-group 
text)))
+                      (column (string-to-number (or (match-string column-group 
text) "0"))))
                  (if (and filename lineno)
-                     (realgud:file-loc-from-line filename lineno
+                     (realgud:file-loc-from-line filename lineno column
                                                  cmd-mark nil nil)
                    nil))
              nil)
@@ -777,7 +798,7 @@ loc-regexp pattern"
     nil))
 
 (defun realgud-track-termination?(text)
-  "Return 't and call `realgud:terminate' we we have a termination message"
+  "Return 't and call realgud:terminate we we have a termination message"
   (if (realgud-cmdbuf?)
       (let ((termination-re (realgud-cmdbuf-pat "termination"))
            )
@@ -843,6 +864,7 @@ find a location. non-nil if we can find a location.
                                (realgud-loc-pat-regexp loc-pat)
                                (realgud-loc-pat-file-group loc-pat)
                                (realgud-loc-pat-line-group loc-pat)
+                               (realgud-loc-pat-column-group loc-pat)
                                nil
                                ))
       (if (stringp loc)
@@ -853,7 +875,8 @@ find a location. non-nil if we can find a location.
   )
 
 (defun realgud:populate-command-hash(key value)
-  "Adds a KEY and VALUE to the realgud-command-name-hash the command name to a 
debugger specific command."
+  "Adds a KEY and VALUE to the realgud-command-name-hash the
+ command name to a debugger specific command."
   (puthash key
            (replace-regexp-in-string "%.*" "" (car (split-string value " ")))
            realgud-command-name-hash))
@@ -909,16 +932,16 @@ we can't find a debugger with that information.`.
 (defun realgud-goto-line-for-pt-and-type (pt type pat-hash)
   "Position the source code at the location that is matched by
 PAT-HASH with key TYPE. The line at PT is used as the string
-to match against and has location info embedded in it"
+to match against and has location info embedded in it."
   (realgud-goto-line-for-loc-pat pt (gethash type pat-hash)))
 
 
 (defun realgud-goto-line-for-pt (pt pattern-key)
   "Position the source code at the location indicated by a
 pattern found in the command buffer with pattern-key
-PATTERN-KEY. (PATTERN-KEY is something like 'debugger-backtrace'
-or 'loc'.) The line at PT is used as the string to match against
-and has location info embedded in it"
+PATTERN-KEY. (PATTERN-KEY is something like debugger-backtrace
+or loc.) The line at PT is used as the string to match against
+and has location info embedded in it."
   (interactive "d")
   (unless (realgud-cmdbuf?)
     (error "You need to be in a debugger command buffer to run this"))
diff --git a/realgud/lang/python.el b/realgud/lang/python.el
index ed92146acf..61b32c722b 100644
--- a/realgud/lang/python.el
+++ b/realgud/lang/python.el
@@ -75,7 +75,7 @@ traceback) line."  )
        :file-group 1
        :line-group 2
        :column-group 3
-       :text-group 3
+       :text-group 4
        :ignore-file-re  realgud-python-ignore-file-re)
       "A realgud-loc-pat struct that describes a Python trepan
       location line."  )
diff --git a/test/test-file.el b/test/test-file.el
index 15cc855439..d11fb7a38d 100644
--- a/test/test-file.el
+++ b/test/test-file.el
@@ -1,5 +1,5 @@
 ;; Press C-x C-e at the end of the next line to run this file test 
non-interactively
-;; (test-simple-run "emacs -batch -L %s -l %s" (file-name-directory 
(locate-library "test-simple.elc")) buffer-file-name)
+;; (test-simple-run "emacs -batch -L %s -L %s -L %s -l %s" 
(file-name-directory (locate-library "test-simple.elc")) (file-name-directory 
(locate-library "load-relative.elc")) (file-name-directory (locate-library 
"loc-changes.elc")) buffer-file-name)
 
 (require 'test-simple)
 (load-file "../realgud/common/loc.el")
diff --git a/test/test-lang.el b/test/test-lang.el
index 72f775c152..c67df578d8 100644
--- a/test/test-lang.el
+++ b/test/test-lang.el
@@ -1,5 +1,6 @@
 ;; Press C-x C-e at the end of the next line to run this file test 
non-interactively
-;; (test-simple-run "emacs -batch -L %s -l %s" (file-name-directory 
(locate-library "test-simple.elc")) buffer-file-name)
+;; (test-simple-run "emacs -batch -L %s -L %s -L %s -l %s" 
(file-name-directory (locate-library "test-simple.elc")) (file-name-directory 
(locate-library "load-relative.elc")) (file-name-directory (locate-library 
"loc-changes.elc")) buffer-file-name)
+
 
 (require 'test-simple)
 (require 'load-relative)

Reply via email to