+commentary

This commit is contained in:
Thomas von Dein
2017-07-22 18:54:35 +02:00
parent af1266d946
commit ab0740861e

View File

@@ -1,5 +1,52 @@
;;; followcursor-mode.el --- highlight line in other buffer containing word in current buffer
;; Copyright (C) 2017, T.v.Dein <tlinden@cpan.org>
;; This file is NOT part of Emacs.
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of the
;; License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
;; USA
;; Version: 0.01
;; Author: T.v.Dein <tlinden@cpan.org>
;; Keywords: files
;; URL: https://github.com/tlinden/followcursor
;; License: GNU General Public License >= 2
;;; Commentary:
;; To use, first add to your config:
;; (require 'followcursor-mode
;; Then prepare two windows with different buffers, enable the mode
;; in one of them with:
;; (followcursor-mode)
;; Move around in that buffer as you wish. Whenever `point' is on a
;; match, it will be highlighted in both buffers.
;;; Code:
;;;; Deps
(require 'hi-lock)
;;;; Customizables
(defgroup followcursor nil
"Follow Cursoe Mode."
:prefix "followcursor-"
@@ -17,10 +64,7 @@
Use the default or someting like:
'(lambda() (thing-at-point 'word))")
;; FIXME: implement ;;;;;;;;;;;
(defcustom followcursor-ask-for-regex nil
"If set to t, ask for regex on mode start to use for marking.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Variables
(make-variable-buffer-local
(defvar followcursor--last-point nil
@@ -30,6 +74,8 @@ Use the default or someting like:
(defvar followcursor-previous-thing nil
"Buffer local variable storing last thing at point, if any"))
;;;; Internal Functions
(defun followcursor--setup-ok ()
"Indicate if it is ok to run followcursor.
Return t if there are currently 2 visible windows."
@@ -38,13 +84,6 @@ Return t if there are currently 2 visible windows."
t
nil))
(defun followcursor-remove-highlights ()
(interactive)
(hi-lock-mode 0)
(other-window 1)
(hi-lock-mode 0)
(other-window 1))
(defun followcursor--mark-and-highlight (mark-what hl-here hl-there)
"Marks thing at point using form ''WHAT and highlights using form ''WHICH."
(interactive)
@@ -64,6 +103,15 @@ Return t if there are currently 2 visible windows."
(setq followcursor-previous-thing thing))
(followcursor-remove-highlights)))))
;;;; Public Functions
(defun followcursor-remove-highlights ()
(interactive)
(hi-lock-mode 0)
(other-window 1)
(hi-lock-mode 0)
(other-window 1))
(defun followcursor-mark-symbol-lazy ()
"Mark symbol at point, be tolerant about what constitutes a symbol."
(interactive)
@@ -72,9 +120,10 @@ Return t if there are currently 2 visible windows."
(end nil))
(when (not (looking-at "[ \t\n]"))
(save-excursion
(backward-word)
(while (looking-back "[-_\.]")
(backward-word))
(unless (looking-back "[ \t\n]")
(backward-word)
(while (looking-back "[-_\.]")
(backward-word)))
(setq beg (point))
(forward-word)
(while (looking-at "[-_\.]")
@@ -113,13 +162,7 @@ and use `followcursor-highlight-there' for marking in the other window."
followcursor-highlight-here
followcursor-highlight-there))))))
(defun fcmh ()
(interactive)
(followcursor--mark-and-highlight
followcursor-mark-thing
followcursor-highlight-here
followcursor-highlight-there)
)
;;;; Minor Mode
;;;###autoload
(define-minor-mode followcursor-mode
@@ -134,5 +177,5 @@ and use `followcursor-highlight-there' for marking in the other window."
(provide 'followcursor-mode)
;; followcursor-mode.el ends here
;;; followcursor-mode.el ends here