I have added the following definitions to my initialization file in order to make the mark show up as a red highlight:
(defface mmv-face
'((t :inherit default :background "red"))
"Face used for showing the mark's position.")
(defvar mmv-mark-overlay nil "Overlay for showing the mark's position.")
(make-variable-buffer-local 'mmv-mark-overlay)
;; The three optional arguments are needed to cover the optional arguments of
;; those functions that this function will modify through `advice-add'.
(defun mmv-show-mark (&optional ARG1 ARG2 ARG3)
"Make the mark's position stand out by means of a one-character-long overlay."
(unless mmv-mark-overlay
(setq mmv-mark-overlay (make-overlay 0 0 nil t))
(overlay-put mmv-mark-overlay 'face 'mmv-face))
(let ((mark-position (mark t)))
(when mark-position
; Function `mark' returns non-nil only if the buffer's mark is set, so
; doing the following is pointless if `mark-position' is nil.
(move-overlay mmv-mark-overlay mark-position (1+ mark-position)))))
(advice-add 'set-mark :after #'mmv-show-mark)
(advice-add 'pop-mark :after #'mmv-show-mark)
(advice-add 'push-mark :after #'mmv-show-mark)
It works well otherwise, except that if the mark is at the end of a line, everything to the right of the mark is also highlighted; see the screenshot below. Why would this be, and how can it be fixed?
\n
/10
and if so, then don't place an overlay spanning that line-end? Alternatively, for line ends you could use a floating overlay with theafter-string
property -- in which case the overlay would not span a full point, but rather the BEG/END would be the same point. You can set the width of a floating overlayafter-string
too. – lawlist Sep 10 '18 at 13:59:inherit default
? – Stefan Sep 10 '18 at 14:03after-string
property. – Teemu Leisti Sep 10 '18 at 14:47