Hi all,

Here is implementation of '(evil-show-marks)', hence ':marks'. Seems
like there is ex command declared for some time, but without
implementation.

'(evil-show-marks)' follows Vim-like look displaying mark character,
row/column and filename for every buffer. Result will be shown in
temporary, *evil-marks* buffer.

Although I tested it, another pair of eyes for review and testing will
be highly welcome :)

Best regards,
Sanel
diff --git a/evil-commands.el b/evil-commands.el
index 9f631ab..446d635 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -2692,6 +2692,48 @@ the previous shell command is executed instead."
                           (cdr reg))))
         (newline)))))
 
+(evil-define-command evil-show-marks ()
+  "Shows all marks."
+  :repeat nil
+  ;; To get markers and positions, we can't rely on 'global-mark-ring' provided
+  ;; by Emacs (although it will be much simpler and faster), because 'global-mark-ring'
+  ;; does not store mark characters, but only buffer name and position. Instead,
+  ;; 'evil-markers-alist' is used; this is list maintained by Evil for each buffer.
+  (let (;; calculate row/col from given point applying on current buffer
+        (line-col #'(lambda (p)
+                      (save-excursion
+                        (goto-char p)
+                        (cons
+                         (1+ (count-lines 1 (point)))
+                         (current-column)))))
+        ;; contains list of vectors in form [char row col filename]
+        (all-markers '()))
+    (save-current-buffer
+     (dolist (b (buffer-list))
+       (set-buffer b)
+       (let ((markers (evil-filter-list #'(lambda (x)
+                                            (not (markerp (cdr x))))
+                                        evil-markers-alist)))
+         (when markers
+           (dolist (m markers)
+             ;; calculate details as soon as possible as '(line-col)' depends
+             ;; on currently selected buffer
+             (let* ((marker (cdr m))
+                    (pos    (funcall line-col (marker-position marker)))
+                    (row    (car pos))
+                    (col    (cdr pos))
+                    (char   (string (car m)))
+                    (file   (buffer-name (marker-buffer marker))))
+               (push (vector char row col file) all-markers)))))))
+    (evil-with-view-list "evil-marks"
+      (setq truncate-lines t)
+      (dolist (m all-markers)
+        (insert (format "\"%s %4d %4d %s\n"
+                        (aref m 0)
+                        (aref m 1)
+                        (aref m 2)
+                        (aref m 3)))))))
+
 (eval-when-compile (require 'ffap))
 (evil-define-command evil-find-file-at-point-with-line ()
   "Opens the file at point and goes to line-number."
_______________________________________________
implementations-list mailing list
[email protected]
https://lists.ourproject.org/cgi-bin/mailman/listinfo/implementations-list

Reply via email to