Skip to content

Commit

Permalink
[Emacs bug] Advice push-mark (#1891)
Browse files Browse the repository at this point in the history
* helm-lib.el (helm--advice-push-mark): New advice enabled.
  • Loading branch information
thierryvolpiatto committed Oct 28, 2017
1 parent ece8972 commit ffd2abf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions helm-lib.el
Expand Up @@ -227,6 +227,38 @@ When only `add-text-properties' is available APPEND is ignored."
file
(and file (> (length file) 0)
(expand-file-name file (dired-current-directory)))))))

;;; Override `push-mark'
;;
;; Fix duplicates in `mark-ring' and `global-mark-ring' and update
;; buffers in `global-mark-ring' to recentest mark.
(defun helm--advice-push-mark (&optional location nomsg activate)
(unless (null (mark t))
(let ((marker (copy-marker (mark-marker))))
(setq mark-ring (cons marker (delete marker mark-ring))))
(when (> (length mark-ring) mark-ring-max)
;; Move marker to nowhere.
(set-marker (car (nthcdr mark-ring-max mark-ring)) nil)
(setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))
(set-marker (mark-marker) (or location (point)) (current-buffer))
;; Now push the mark on the global mark ring.
(setq global-mark-ring (cons (copy-marker (mark-marker))
;; Avoid having multiple entries
;; for same buffer in `global-mark-ring'.
(cl-loop with mb = (current-buffer)
for m in global-mark-ring
for nmb = (marker-buffer m)
unless (eq mb nmb)
collect m)))
(when (> (length global-mark-ring) global-mark-ring-max)
(set-marker (car (nthcdr global-mark-ring-max global-mark-ring)) nil)
(setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil))
(or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
(message "Mark set"))
(when (or activate (not transient-mark-mode))
(set-mark (mark t)))
nil)
(advice-add 'push-mark :override #'helm--advice-push-mark)

;;; Macros helper.
;;
Expand Down

0 comments on commit ffd2abf

Please sign in to comment.