From cfa1824e2674ca83f7d8b543889ce7d77003858b Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 18 Apr 2015 14:42:11 +0100 Subject: [PATCH] el/dot-emacs.el (experimental): Show fringe icon on current line. Much of the machinery comes from https://github.com/kyanagi/fringe-current-line but the trimmings are a little different. Most notably, there is only one marker, in the selected window. (Otherwise the marker would need to be per-window rather than per-buffer, because each window has its own idea of point, and things get rather complicated.) --- el/dot-emacs.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 3440c82..f917905 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -872,6 +872,58 @@ doesn't match any of the regular expressions in (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights) ;;;-------------------------------------------------------------------------- +;;; Where is point? + +(defvar mdw-point-overlay + (let ((ov (make-overlay 0 0)) + (s ".")) + (overlay-put ov 'priority 2) + (put-text-property 0 1 'display '(left-fringe vertical-bar) s) + (overlay-put ov 'before-string s) + (delete-overlay ov) + ov) + "An overlay used for showing where point is in the selected window.") + +(defun mdw-remove-point-overlay () + "Remove the current-point overlay." + (delete-overlay mdw-point-overlay)) + +(defun mdw-update-point-overlay () + "Mark the current point position with an overlay." + (if (not mdw-point-overlay-mode) + (mdw-remove-point-overlay) + (overlay-put mdw-point-overlay 'window (selected-window)) + (move-overlay mdw-point-overlay (point) (1+ (point)) (current-buffer)))) + +(defvar mdw-point-overlay-buffers nil + "List of buffers using `mdw-point-overlay-mode'.") + +(define-minor-mode mdw-point-overlay-mode + "Indicate current line with an overlay." + :global nil + (let ((buffer (current-buffer))) + (setq mdw-point-overlay-buffers + (mapcan (lambda (buf) + (if (and (buffer-live-p buf) + (not (eq buf buffer))) + (list buf))) + mdw-point-overlay-buffers)) + (if mdw-point-overlay-mode + (setq mdw-point-overlay-buffers + (cons buffer mdw-point-overlay-buffers)))) + (cond (mdw-point-overlay-buffers + (add-hook 'pre-command-hook 'mdw-remove-point-overlay) + (add-hook 'post-command-hook 'mdw-update-point-overlay)) + (t + (mdw-remove-point-overlay) + (remove-hook 'pre-command-hook 'mdw-remove-point-overlay) + (remove-hook 'post-command-hook 'mdw-update-point-overlay)))) + +(define-globalized-minor-mode mdw-global-point-overlay-mode + mdw-point-overlay-mode + (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t)))) + +;;;-------------------------------------------------------------------------- ;;; General fontification. (defmacro mdw-define-face (name &rest body) -- 2.11.0