minad / consult

:mag: consult.el - Consulting completing-read
GNU General Public License v3.0
1.12k stars 98 forks source link

consult--global-mark-candidates only stores the location in places that are stripped #929

Closed oantolin closed 3 months ago

oantolin commented 3 months ago

I just noticed that embark-export doesn't work with consult-global-mark, while it does work with consult-mark. I think the difference is that consult--mark-candidates and consult--global-mark-candidates store the consult-location property in different places: consult--mark-candidates puts it on the first character of the line, and consult--global-mark-candidates puts it in the file and line number prefix, which is also marked consult-strip t. Since embark-export uses the transformed candidates, the consult-locations are stripped by the time embark-consult-occur-export sees them.

Do you think you could put the consult-location property on the first character of the line instead?

oantolin commented 3 months ago

I don't remember exactly, but I think this used to work, and then we changed the way stripping tofus worked and didn't notice that affected consult-global-mark export.

oantolin commented 3 months ago

consult--global-mark-candidates should probably use the consult--location-candidate for uniformity with other -candidates functions that produce candidates with category consult-location.

oantolin commented 3 months ago

Thanks for the quick fix. I was about to propose a different fix using consult--location-candidate, but as usual you beat me to the punch. :)

minad commented 3 months ago

I don't think we can use consult--location-candidate since it is too limited.

oantolin commented 3 months ago

I meant concatenating it with the prefix as follows:

diff --git a/consult.el b/consult.el
index 1e69e5c..f3f470b 100644
--- a/consult.el
+++ b/consult.el
@@ -3236,12 +3236,15 @@ The symbol at point is added to the future history."
               (when (consult--in-range-p pos)
                 (goto-char pos)
                 ;; `line-number-at-pos' is slow, see comment in `consult--mark-candidates'.
-                (let* ((line (line-number-at-pos pos consult-line-numbers-widen))
-                       (prefix (consult--format-file-line-match (buffer-name buf) line ""))
-                       (cand (concat prefix (consult--line-with-mark marker) (consult--tofu-encode marker))))
-                  (put-text-property 0 (length prefix) 'consult-strip t cand)
-                  (put-text-property 0 (length cand) 'consult-location (cons marker line) cand)
-                  (push cand candidates))))))))
+                (let ((line (line-number-at-pos pos consult-line-numbers-widen)))
+                  (push (concat
+                         (propertize
+                          (consult--format-file-line-match (buffer-name buf) line "")
+                          'consult-location (cons marker line)
+                          'consult-strip t)
+                         (consult--location-candidate
+                          (consult--line-with-mark marker) marker line marker))
+                        candidates))))))))
     (unless candidates
       (user-error "No global marks"))
     (nreverse (delete-dups candidates))))

But I don't really think that's very different from what you did.

minad commented 3 months ago

Omar Antolín Camarena @.***> writes:

I meant concatenating it with the prefix as follows:

Alright. This would work, but would be slightly less efficient. Not that it matters for consult-global-mark.