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

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

[nongnu] elpa/annotate 9aba6305fe 342/372: Merge pull request #109 from


From: ELPA Syncer
Subject: [nongnu] elpa/annotate 9aba6305fe 342/372: Merge pull request #109 from cage2/fix-replace-button
Date: Fri, 4 Feb 2022 16:59:20 -0500 (EST)

branch: elpa/annotate
commit 9aba6305fef54f32b085a56ce2b843b3d8194ac2
Merge: b22f594f3b de86b9b22e
Author: cage2 <1257703+cage2@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #109 from cage2/fix-replace-button
    
    Fixed callback for "[replace]" button in summary window
---
 Changelog   |  23 +++++++++++++
 NEWS.org    |  13 ++++++++
 annotate.el | 108 ++++++++++++++++++++++++++++++++++++++++++------------------
 3 files changed, 112 insertions(+), 32 deletions(-)

diff --git a/Changelog b/Changelog
index 33999c0519..7fd9dcbef4 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,26 @@
+2021-05-27  cage
+
+        * annotate.el:
+
+       - fixed annotated text shown in the summary window
+
+       When an annotated buffer (that is  visiting a file) is modified in
+       a way that  changes the position of an annotation  in that buffer,
+       showing the  summary window -without  saving the file  first- will
+       read the  annotation using the  updated position but will  get the
+       contents from the  outdated file; this gives wrong  results in the
+       text  annotation  parts of  the  summary  windows, with  the  text
+       shifted from  the correct  position.  This patch  try to  fix this
+       bug.
+
+2021-05-26  cage
+
+        * annotate.el:
+
+       - fixed  callback for  "[replace]" button  in summary  window; the
+       callback  function  was  neither properly  saving  the  annotation
+       database nor refreshing the buffer's annotations.
+
 2021-05-07  cage
 
         * annotate.el:
diff --git a/NEWS.org b/NEWS.org
index 3e9c0eb0dc..21727e1391 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -243,3 +243,16 @@
   Before  deleting the  old database  file a  confirmation message  is
   printed    on    the    minibuffer   if    the    custom    variable
   'annotate-database-confirm-deletion' is non nil (default: t).
+
+- 2021-05-27 V1.3.1 cage ::
+
+  Bugfix release:
+
+  - The  button "[replace]"  to edit  an annotation  from the  summary
+    window was not working at all;
+
+  - In certain  cases the  summary window  was rendering  wrong text's
+    fragment instead of the text of the annotation.
+
+  Many thanks  to "glvno"  for reporting  the aforementioned  bugs and
+  testing the patches!
diff --git a/annotate.el b/annotate.el
index 2295d2b19a..3c70169f14 100644
--- a/annotate.el
+++ b/annotate.el
@@ -7,7 +7,7 @@
 ;; Maintainer: Bastian Bechtold
 ;; URL: https://github.com/bastibe/annotate.el
 ;; Created: 2015-06-10
-;; Version: 1.3.0
+;; Version: 1.3.1
 
 ;; This file is NOT part of GNU Emacs.
 
@@ -58,7 +58,7 @@
 ;;;###autoload
 (defgroup annotate nil
   "Annotate files without changing them."
-  :version "1.3.0"
+  :version "1.3.1"
   :group 'text)
 
 ;;;###autoload
@@ -2338,6 +2338,13 @@ sophisticated way than plain text"
         (with-current-buffer buffer
           (goto-char (button-get button 'go-to))))))))
 
+(defun annotate-update-visited-buffer-maybe (filename)
+  (let ((visited-buffer (find-buffer-visiting filename)))
+    (when visited-buffer ;; a buffer is visiting the file
+      (with-current-buffer visited-buffer
+        (annotate-mode -1)
+        (annotate-mode  1)))))
+
 (defun annotate-summary-delete-annotation-button-pressed (button)
  "Callback for summary window fired when a 'delete' button is
 pressed."
@@ -2358,20 +2365,12 @@ pressed."
                         (button-put annotation-button 'face '(:strike-through 
t)))
                       (let ((replace-button (next-button (point))))
                         (button-put replace-button 'invisible t)))
-                    (read-only-mode 1)))
-                ;; if the file where the  deleted annotation belong to is 
visited,
-                ;; update the buffer
-                (update-visited-buffer-maybe ()
-                  (let ((visited-buffer (find-buffer-visiting filename)))
-                    (when visited-buffer ;; a buffer is visiting the file
-                      (with-current-buffer visited-buffer
-                        (annotate-mode -1)
-                        (annotate-mode  1))))))
+                    (read-only-mode 1))))
       (redraw-summary-window)
-      (update-visited-buffer-maybe))))
+      (annotate-update-visited-buffer-maybe filename))))
 
 (defun annotate-summary-replace-annotation-button-pressed (button)
-   "Callback for summary window fired when a 'replace' button is
+  "Callback for summary window fired when a 'replace' button is
 pressed."
   (let* ((filename             (button-get button 'file))
          (annotation-beginning (button-get button 'beginning))
@@ -2387,9 +2386,31 @@ pressed."
                                                                     
annotation-ending
                                                                     
new-annotation-text)))
         (annotate-dump-annotation-data replaced-annotation-db)
-        (annotate-show-annotation-summary query)))))
-
-(defun annotate-show-annotation-summary (&optional arg-query cut-above-point)
+        (annotate-update-visited-buffer-maybe filename)
+        (annotate-show-annotation-summary query nil nil)))))
+
+(cl-defun annotate-wrap-text (text &optional (wrapper "\""))
+  (concat wrapper text wrapper))
+
+(cl-defun annotate-unwrap-text (text &optional (wrapper "\"") (left-side t))
+  (let ((results        text)
+        (wrapper-length (length wrapper)))
+    (when (>= (length text)
+              wrapper-length)
+      (if left-side
+          (let ((maybe-wrapper (substring results 0 wrapper-length)))
+            (when (string= maybe-wrapper wrapper)
+              (setf results (substring results wrapper-length))
+              (setf results (annotate-unwrap-text results wrapper nil))))
+        (let ((maybe-wrapper (substring results
+                                        (- (length results)
+                                           wrapper-length))))
+          (when (string= maybe-wrapper wrapper)
+            (setf results (substring results 0 (- (length results)
+                                                  wrapper-length)))))))
+    results))
+
+(cl-defun annotate-show-annotation-summary (&optional arg-query 
cut-above-point (save-annotations t))
  "Show a summary of all the annotations in a temp buffer, the
 results can be filtered with a simple query language: see
 `annotate-summary-filter-db'."
@@ -2408,7 +2429,7 @@ results can be filtered with a simple query language: see
                                        annotate-ellipse-text-marker)
                              text)))
               (wrap      (text)
-                         (concat "\"" text "\""))
+                         (annotate-wrap-text text "\""))
               (insert-item-summary (filename
                                     snippet-text
                                     button-text
@@ -2470,6 +2491,20 @@ results can be filtered with a simple query language: see
                                     (info-setup filename (current-buffer))
                                     (buffer-substring-no-properties 
annotation-begin
                                                                     
annotation-end)))
+              (build-snippet-from-buffer (filename annotation-begin 
annotation-end)
+                (let ((visited-buffer (find-buffer-visiting filename)))
+                  (when visited-buffer ;; a buffer is visiting the file
+                    (with-current-buffer visited-buffer
+                      (let ((raw-snippet (buffer-substring-no-properties 
annotation-begin
+                                                                         
annotation-end)))
+                        (clean-snippet raw-snippet))))))
+              (build-snippet-from-file (filename annotation-begin 
annotation-end)
+                (with-temp-buffer
+                  (insert-file-contents filename
+                                        nil
+                                        (1- annotation-begin)
+                                        (1- annotation-end))
+                  (clean-snippet (buffer-string))))
               (build-snippet (filename annotation-begin annotation-end)
                              (if (file-exists-p filename)
                                  (cond
@@ -2479,12 +2514,12 @@ results can be filtered with a simple query language: 
see
                                                                       
annotation-begin
                                                                       
annotation-end)))
                                   (t
-                                   (with-temp-buffer
-                                     (insert-file-contents filename
-                                                           nil
-                                                           (1- 
annotation-begin)
-                                                           (1- annotation-end))
-                                     (clean-snippet (buffer-string)))))
+                                   (or (build-snippet-from-buffer filename
+                                                                  
annotation-begin
+                                                                  
annotation-end)
+                                       (build-snippet-from-file   filename
+                                                                  
annotation-begin
+                                                                  
annotation-end))))
                                (if (annotate-info-root-dir-p filename)
                                    (clean-snippet (build-snippet-info filename
                                                                       
annotation-begin
@@ -2503,7 +2538,8 @@ results can be filtered with a simple query language: see
                                (read-from-minibuffer "Query: "))
                               (t
                                ".*"))))
-    (annotate-save-annotations)
+    (when save-annotations
+      (annotate-save-annotations))
     (let* ((filter-query (get-query))
            (dump         (annotate-summary-filter-db 
(annotate-load-annotation-data t)
                                                      filter-query
@@ -2675,6 +2711,10 @@ example:
 `annotate-summary-query'"
   (eq token :no-more-tokens))
 
+(defun annotate-summary-token-symbol-match (looking-symbol token)
+  (eq looking-symbol
+      (annotate-summary-query-lexer-symbol token)))
+
 (cl-defun annotate-summary-query-parse-note (filter-fn annotation &optional 
(res nil))
   "Parser rule for note:
 
@@ -2715,8 +2755,7 @@ Arguments:
 
 "
   (cl-labels ((token-symbol-match-p (looking-symbol token)
-                                    (eq looking-symbol
-                                        (annotate-summary-query-lexer-symbol 
token)))
+                (annotate-summary-token-symbol-match looking-symbol token))
               ;; this function will parse the rule operator
               ;; OPERATOR   := AND | OR
               ;; where
@@ -2871,16 +2910,20 @@ Note: this function returns the annotation part of the 
record, see
   (lambda (annotation query file-filter-fn note-filter-fn)
     (let ((annotate-summary-query query) ; save the query
           (query-notes-only       nil)) ; the query for just the notes
-      (let ((next-token (annotate-summary-lexer))) ; get file-mask
-        ;; if there are no more tokes just return all the records
+      (let ((next-token (annotate-summary-lexer))) ; get potential file-mask
+        ;; if there are no more tokens just return all the records
         ;; these match the empty string as in rule
         ;; EXPRESSION := epsilon
         (if (annotate-summary-query-parse-end-input-p next-token)
             (annotate-annotations-from-dump annotation)
           ;; otherwise test the record with the file-mask
-          (let* ((filtered-annotation (funcall file-filter-fn
-                                               
(annotate-summary-query-lexer-string next-token)
-                                               annotation))
+          (let* ((quoted-file-mask-p  (annotate-summary-token-symbol-match 
'escaped-re
+                                                                           
next-token))
+                 (file-mask-raw       (annotate-summary-query-lexer-string 
next-token))
+                 (file-mask           (if quoted-file-mask-p
+                                          (annotate-unwrap-text file-mask-raw 
"\"")
+                                         file-mask-raw))
+                 (filtered-annotation (funcall file-filter-fn file-mask 
annotation))
                  ;; get the operator as in rule
                  (operator-token (annotate-summary-lexer)))
             ;; if there are no operator just return the filtered (by file-mask)
@@ -3041,7 +3084,8 @@ position."
   (interactive)
   (with-current-buffer (current-buffer)
     (when buffer-file-name
-      (annotate-show-annotation-summary buffer-file-name (point)))))
+      (annotate-show-annotation-summary (annotate-wrap-text buffer-file-name 
"\"")
+                                        (point)))))
 
 ;;; switching database
 



reply via email to

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