-
-
Save zk-phi/78fbfc612bd78abbab21909e2ab5fd10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; taken from init.el | |
;; --- hilit-chg settings | |
(add-hook 'find-file-hook 'highlight-changes-mode) | |
;; start with invisible mode | |
(setq highlight-changes-visibility-initial-state nil) | |
;; clear highlights after save | |
(setup-hook 'after-save-hook | |
(when highlight-changes-mode | |
(save-restriction | |
(widen) | |
(highlight-changes-remove-highlight (point-min) (point-max))))) | |
;; --- anything source for hilit-chg | |
(defun my-change-search-next (point) | |
(let (start tmp) | |
;; if the point is nil, return nil | |
(when point | |
(setq start (if (get-text-property point 'hilit-chg) point | |
(next-single-property-change point 'hilit-chg))) | |
;; if there are no changes more, return nil | |
(when start | |
;; possibly, the end of this change | |
(setq tmp (next-single-property-change start 'hilit-chg)) | |
;; join adjacent changes | |
(while (and tmp (get-text-property tmp 'hilit-chg)) | |
(setq tmp (next-single-property-change tmp 'hilit-chg))) | |
(if tmp (list start tmp) | |
(list start (point-max))))))) | |
(defun my-change-get-string (from to) | |
(let* ((from (save-excursion (goto-char from) | |
(skip-chars-forward "\n") | |
(point))) | |
(to (save-excursion (goto-char to) | |
(skip-chars-backward "\s\t\n") | |
(if (looking-back "[\s\t\n]") | |
(1- (point)) | |
(point)))) | |
(string (buffer-substring from to))) | |
(if (string-match "^[\s\t\n]*$" string) "" | |
string))) | |
(defun my-change-buffer nil) | |
(defun my-change-candidates () | |
(with-current-buffer my-change-buffer | |
(let ((start (point-min)) tmp candidates) | |
(while (setq tmp (my-change-search-next start)) | |
(add-to-list 'candidates | |
(cons (format "%5d:: %s" | |
(line-number-at-pos (car tmp)) | |
(apply 'my-change-get-string tmp)) | |
(car tmp))) | |
;; change start position of search | |
(setq start (cadr tmp))) | |
(reverse candidates)))) | |
(defvar anything-source-highlight-changes-mode | |
'((name . "Changes") | |
(init . (lambda () (setq my-change-buffer (current-buffer)))) | |
(candidates . my-change-candidates) | |
(action . (lambda (num) (goto-char num))) | |
(multiline))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment