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

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

[elpa] master 524047e 163/215: Fix file-column-to-string in the presence


From: Rocky Bernstein
Subject: [elpa] master 524047e 163/215: Fix file-column-to-string in the presence of composed characters
Date: Sat, 30 Jul 2016 14:49:02 +0000 (UTC)

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

    Fix file-column-to-string in the presence of composed characters
    
    (- (current-column) (length source-text)) is not necessarily a valid
    source position: indeed, when a line contains composed characters, these
    characters do not count towards column numbers; thus, the largest column
    on a line containing n characters can be < n, and thus the existing code
    could return negative column numbers.
    
    Concrete example: starting trepan2 on a buffer created by the following
    snippet would cause realgud to crash:
    
        (with-current-buffer (get-buffer-create "*python-prettified*")
          (python-mode)
          (erase-buffer)
          (setq-local prettify-symbols-alist '(("in" . ?∈)))
          (insert "for x in [1,2,3]:\n    pass")
          (prettify-symbols-mode)
          (pop-to-buffer (current-buffer)))
---
 realgud/common/file.el |   28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/realgud/common/file.el b/realgud/common/file.el
index b4c378c..5bbf8ee 100644
--- a/realgud/common/file.el
+++ b/realgud/common/file.el
@@ -29,22 +29,18 @@ found"
   "Return the column of the first column position of SOURCE-TEXT
 at LINE-NUMBER or nil if it is not there"
   (condition-case nil
-      (if (file-exists-p filename)
-         (let ((file-buffer (find-file-noselect filename)))
-           (with-current-buffer-safe file-buffer
-             (save-excursion
-               (goto-char (point-min))
-               (forward-line (1- line-number))
-               (unless no-strip-blanks
-                 (setq source-text (realgud:strip source-text)))
-               (if (search-forward source-text (point-at-eol))
-                   (- (current-column)
-                      (length source-text))))))
-       ;; else
-       nil)
-    (error nil))
-)
-
+      (when (and source-text (file-exists-p filename))
+        (let ((file-buffer (find-file-noselect filename)))
+          (with-current-buffer-safe file-buffer
+            (save-excursion
+              (goto-char (point-min))
+              (forward-line (1- line-number))
+              (unless no-strip-blanks
+                (setq source-text (realgud:strip source-text)))
+              (when (search-forward source-text (point-at-eol))
+                (goto-char (match-beginning 0))
+                (current-column))))))
+    (error nil)))
 
 ;; FIXME: should allow column number to be passed in.
 (defun realgud:file-loc-from-line(filename line-number



reply via email to

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