[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/idle-highlight-mode 9976d951f5 07/16: Cleanup: emacs nativ
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/idle-highlight-mode 9976d951f5 07/16: Cleanup: emacs native format |
Date: |
Tue, 7 Feb 2023 23:59:17 -0500 (EST) |
branch: elpa/idle-highlight-mode
commit 9976d951f5e93813bd6cfdc745d7bec985fa5986
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Cleanup: emacs native format
---
idle-highlight-mode.el | 285 +++++++++++++++++++++++--------------------------
1 file changed, 135 insertions(+), 150 deletions(-)
diff --git a/idle-highlight-mode.el b/idle-highlight-mode.el
index 4a35766488..a01335c551 100755
--- a/idle-highlight-mode.el
+++ b/idle-highlight-mode.el
@@ -53,16 +53,14 @@
(defcustom idle-highlight-exceptions nil
"List of words to be excepted from highlighting."
:type
- '
- (choice
+ '(choice
(repeat :tag "A list of string literals that will be excluded." string)
(function :tag "A function taking a string, non-nil result excludes.")))
(defcustom idle-highlight-exceptions-face '(font-lock-keyword-face
font-lock-string-face)
"List of exception faces."
:type
- '
- (choice
+ '(choice
(repeat :tag "A list of face symbols that will be ignored." symbol)
(function :tag "A function that takes a list of faces, non-nil result
excludes.")))
@@ -110,18 +108,18 @@ check this buffer.")
"Add the named faces that the `read-face-name' or `face' property use.
Argument POS return faces at this point."
(let
- ( ;; List of faces to return.
- (faces nil)
- ;; NOTE: use `get-text-property' instead of `get-char-property' so
overlays are excluded,
- ;; since this causes overlays with `hl-line-mode' (for example) to mask
keywords, see: #1.
- (faceprop (or (get-text-property pos 'read-face-name) (get-text-property
pos 'face))))
+ ( ;; List of faces to return.
+ (faces nil)
+ ;; NOTE: use `get-text-property' instead of `get-char-property' so
overlays are excluded,
+ ;; since this causes overlays with `hl-line-mode' (for example) to mask
keywords, see: #1.
+ (faceprop (or (get-text-property pos 'read-face-name)
(get-text-property pos 'face))))
(cond
- ((facep faceprop)
- (push faceprop faces))
- ((face-list-p faceprop)
- (dolist (face faceprop)
- (when (facep face)
- (push face faces)))))
+ ((facep faceprop)
+ (push faceprop faces))
+ ((face-list-p faceprop)
+ (dolist (face faceprop)
+ (when (facep face)
+ (push face faces)))))
faces))
(defun idle-highlight--merge-overlapping-ranges (ranges)
@@ -129,35 +127,31 @@ Argument POS return faces at this point."
Where RANGES is an unordered list of (min . max) cons cells."
(cond
- ((cdr ranges)
- ;; Simple < sorting of cons cells.
- (setq ranges
- (sort
- ranges
- (lambda (x y) (or (< (car x) (car y)) (and (= (car x) (car y)) (<
(cdr x) (cdr y)))))))
- ;; Step over `ranges', de-duplicating & adjusting elements as needed.
- (let
- (
- (ranges-iter ranges)
+ ((cdr ranges)
+ ;; Simple < sorting of cons cells.
+ (setq ranges
+ (sort
+ ranges
+ (lambda (x y) (or (< (car x) (car y)) (and (= (car x) (car y)) (<
(cdr x) (cdr y)))))))
+ ;; Step over `ranges', de-duplicating & adjusting elements as needed.
+ (let ((ranges-iter ranges)
(ranges-next (cdr ranges)))
- (while ranges-next
- (let
- (
- (head (car ranges-iter))
+ (while ranges-next
+ (let ((head (car ranges-iter))
(next (car ranges-next)))
- (cond
- ((< (cdr head) (car next))
- (setq ranges-iter ranges-next)
- (setq ranges-next (cdr ranges-next)))
- (t
- (when (< (cdr head) (cdr next))
- (setcdr head (cdr next)))
- (setq ranges-next (cdr ranges-next))
- (setcdr ranges-iter ranges-next)))))
- ranges))
+ (cond
+ ((< (cdr head) (car next))
+ (setq ranges-iter ranges-next)
+ (setq ranges-next (cdr ranges-next)))
+ (t
+ (when (< (cdr head) (cdr next))
+ (setcdr head (cdr next)))
+ (setq ranges-next (cdr ranges-next))
+ (setcdr ranges-iter ranges-next)))))
+ ranges))
- (t ;; No need for complex logic single/empty lists.
- ranges)))
+ (t ;; No need for complex logic single/empty lists.
+ ranges)))
;; ---------------------------------------------------------------------------
@@ -166,41 +160,41 @@ Where RANGES is an unordered list of (min . max) cons
cells."
(defun idle-highlight--check-symbol-at-point (pos)
"Return non-nil if the symbol at POS can be used."
(cond
- (idle-highlight-exceptions-syntax
- (save-excursion (zerop (skip-syntax-forward
idle-highlight-exceptions-syntax (1+ pos)))))
- (t
- t)))
+ (idle-highlight-exceptions-syntax
+ (save-excursion (zerop (skip-syntax-forward
idle-highlight-exceptions-syntax (1+ pos)))))
+ (t
+ t)))
(defun idle-highlight--check-faces-at-point (pos)
"Check if the position POS has faces that match the exclude argument."
(cond
- (idle-highlight-exceptions-face
- (let ((result t))
- (let ((faces-at-pos (idle-highlight--faces-at-point pos)))
- (when faces-at-pos
- (cond
- ((functionp idle-highlight-exceptions-face)
- (when (funcall idle-highlight-exceptions-face faces-at-pos)
- (setq result nil)))
- (t
- (while faces-at-pos
- (let ((face (pop faces-at-pos)))
- (when (memq face idle-highlight-exceptions-face)
- (setq result nil)
- ;; Break.
- (setq faces-at-pos nil))))))))
- result))
- (t ;; Default to true, if there are no exceptions.
- t)))
+ (idle-highlight-exceptions-face
+ (let ((result t))
+ (let ((faces-at-pos (idle-highlight--faces-at-point pos)))
+ (when faces-at-pos
+ (cond
+ ((functionp idle-highlight-exceptions-face)
+ (when (funcall idle-highlight-exceptions-face faces-at-pos)
+ (setq result nil)))
+ (t
+ (while faces-at-pos
+ (let ((face (pop faces-at-pos)))
+ (when (memq face idle-highlight-exceptions-face)
+ (setq result nil)
+ ;; Break.
+ (setq faces-at-pos nil))))))))
+ result))
+ (t ;; Default to true, if there are no exceptions.
+ t)))
(defun idle-highlight--check-word (target)
"Return non-nil when TARGET should not be excluded."
(not
- (cond
- ((functionp idle-highlight-exceptions)
- (funcall idle-highlight-exceptions target))
- (t
- (member target idle-highlight-exceptions)))))
+ (cond
+ ((functionp idle-highlight-exceptions)
+ (funcall idle-highlight-exceptions target))
+ (t
+ (member target idle-highlight-exceptions)))))
;; ---------------------------------------------------------------------------
@@ -222,15 +216,11 @@ Argument VISIBLE-RANGES is a list of (min . max) ranges
to highlight."
(pcase-dolist (`(,beg . ,end) visible-ranges)
(goto-char beg)
(while (re-search-forward target-regexp end t)
- (let
- (
- (match-beg (match-beginning 0))
- (match-end (match-end 0)))
- (unless
- (and
- idle-highlight-exclude-point
- (eq target-beg match-beg)
- (eq target-end match-end))
+ (let ((match-beg (match-beginning 0))
+ (match-end (match-end 0)))
+ (unless (and idle-highlight-exclude-point
+ (eq target-beg match-beg)
+ (eq target-end match-end))
(let ((ov (make-overlay match-beg match-end)))
(overlay-put ov 'face 'idle-highlight)
(push ov idle-highlight--overlays)))))))))
@@ -284,20 +274,20 @@ should be the result of
`idle-highlight--word-at-point-args'."
"Callback that run the repeat timer."
(let
- ( ;; Ensure all other buffers are highlighted on request.
- (is-mode-active (bound-and-true-p idle-highlight-mode))
- (buf-current (current-buffer))
- (dirty-buffer-list (list))
- (force-all idle-highlight-visible-buffers))
+ ( ;; Ensure all other buffers are highlighted on request.
+ (is-mode-active (bound-and-true-p idle-highlight-mode))
+ (buf-current (current-buffer))
+ (dirty-buffer-list (list))
+ (force-all idle-highlight-visible-buffers))
;; When this buffer is not in the mode, flush all other buffers.
(cond
- (is-mode-active
- (setq idle-highlight--dirty t))
- (t
- ;; If the timer ran when in another buffer,
- ;; a previous buffer may need a final refresh, ensure this happens.
- (setq idle-highlight--dirty-flush-all t)))
+ (is-mode-active
+ (setq idle-highlight--dirty t))
+ (t
+ ;; If the timer ran when in another buffer,
+ ;; a previous buffer may need a final refresh, ensure this happens.
+ (setq idle-highlight--dirty-flush-all t)))
(when force-all
(setq idle-highlight--dirty-flush-all t))
@@ -307,14 +297,12 @@ should be the result of
`idle-highlight--word-at-point-args'."
(dolist (frame (frame-list))
(dolist (win (window-list frame -1))
(let ((buf (window-buffer win)))
- (when
- (cond
- (idle-highlight--dirty-flush-all
- (and
- (buffer-local-value 'idle-highlight-mode buf)
- (or (buffer-local-value 'idle-highlight--dirty buf)
force-all)))
- (t
- (eq buf buf-current)))
+ (when (cond
+ (idle-highlight--dirty-flush-all
+ (and (buffer-local-value 'idle-highlight-mode buf)
+ (or (buffer-local-value 'idle-highlight--dirty buf)
force-all)))
+ (t
+ (eq buf buf-current)))
(unless (memq buf dirty-buffer-list)
(push buf dirty-buffer-list))
@@ -325,15 +313,14 @@ should be the result of
`idle-highlight--word-at-point-args'."
;; Push a (min . max) cons cell,
;; expanded to line bounds (to avoid clipping words).
(save-excursion
- (push
- (cons
- (progn
- (goto-char (max (point-min) (window-start win)))
- (line-beginning-position))
- (progn
- (goto-char (min (point-max) (window-end win)))
- (line-end-position)))
- idle-highlight--dirty)))))))
+ (push (cons
+ (progn
+ (goto-char (max (point-min) (window-start win)))
+ (line-beginning-position))
+ (progn
+ (goto-char (min (point-max) (window-end win)))
+ (line-end-position)))
+ idle-highlight--dirty)))))))
(let ((target-args (and force-all (idle-highlight--word-at-point-args))))
@@ -354,37 +341,37 @@ should be the result of
`idle-highlight--word-at-point-args'."
(idle-highlight--word-at-point-highlight target target-range
visible-ranges))))))
(cond
- (is-mode-active
- ;; Always keep the current buffer dirty
- ;; so navigating away from this buffer will refresh it.
- (setq idle-highlight--dirty t))
- (t ;; Cancel the timer until the current buffer uses this mode again.
- (idle-highlight--time-ensure nil)))))
+ (is-mode-active
+ ;; Always keep the current buffer dirty
+ ;; so navigating away from this buffer will refresh it.
+ (setq idle-highlight--dirty t))
+ (t ;; Cancel the timer until the current buffer uses this mode again.
+ (idle-highlight--time-ensure nil)))))
(defun idle-highlight--time-ensure (state)
"Ensure the timer is enabled when STATE is non-nil, otherwise disable."
(cond
- (state
- (unless idle-highlight--global-timer
- (setq idle-highlight--global-timer
- (run-with-idle-timer
- idle-highlight-idle-time
- :repeat #'idle-highlight--time-callback-or-disable))))
- (t
- (when idle-highlight--global-timer
- (cancel-timer idle-highlight--global-timer)
- (setq idle-highlight--global-timer nil)))))
+ (state
+ (unless idle-highlight--global-timer
+ (setq idle-highlight--global-timer
+ (run-with-idle-timer
+ idle-highlight-idle-time
+ :repeat #'idle-highlight--time-callback-or-disable))))
+ (t
+ (when idle-highlight--global-timer
+ (cancel-timer idle-highlight--global-timer)
+ (setq idle-highlight--global-timer nil)))))
(defun idle-highlight--time-reset ()
"Run this when the buffer change was changed."
;; Ensure changing windows doesn't leave other buffers with stale highlight.
(cond
- ((bound-and-true-p idle-highlight-mode)
- (setq idle-highlight--dirty-flush-all t)
- (setq idle-highlight--dirty t)
- (idle-highlight--time-ensure t))
- (t
- (idle-highlight--time-ensure nil))))
+ ((bound-and-true-p idle-highlight-mode)
+ (setq idle-highlight--dirty-flush-all t)
+ (setq idle-highlight--dirty t)
+ (idle-highlight--time-ensure t))
+ (t
+ (idle-highlight--time-ensure nil))))
(defun idle-highlight--time-buffer-local-enable ()
"Ensure buffer local state is enabled."
@@ -416,25 +403,23 @@ should be the result of
`idle-highlight--word-at-point-args'."
(defun idle-highlight--turn-on ()
"Enable command `idle-highlight-mode'."
- (when
- (and
- ;; Not already enabled.
- (not (bound-and-true-p idle-highlight-mode))
- ;; Not in the mini-buffer.
- (not (minibufferp))
- ;; Not a special mode (package list, tabulated data ... etc)
- ;; Instead the buffer is likely derived from `text-mode' or `prog-mode'.
- (not (derived-mode-p 'special-mode))
- ;; Not explicitly ignored.
- (not (memq major-mode idle-highlight-ignore-modes))
- ;; Optionally check if a function is used.
- (or
- (null global-idle-highlight-ignore-buffer)
- (cond
- ((functionp global-idle-highlight-ignore-buffer)
- (not (funcall global-idle-highlight-ignore-buffer
(current-buffer))))
- (t
- nil))))
+ (when (and
+ ;; Not already enabled.
+ (not (bound-and-true-p idle-highlight-mode))
+ ;; Not in the mini-buffer.
+ (not (minibufferp))
+ ;; Not a special mode (package list, tabulated data ... etc)
+ ;; Instead the buffer is likely derived from `text-mode' or
`prog-mode'.
+ (not (derived-mode-p 'special-mode))
+ ;; Not explicitly ignored.
+ (not (memq major-mode idle-highlight-ignore-modes))
+ ;; Optionally check if a function is used.
+ (or (null global-idle-highlight-ignore-buffer)
+ (cond
+ ((functionp global-idle-highlight-ignore-buffer)
+ (not (funcall global-idle-highlight-ignore-buffer
(current-buffer))))
+ (t
+ nil))))
(idle-highlight-mode 1)))
@@ -447,10 +432,10 @@ should be the result of
`idle-highlight--word-at-point-args'."
:global nil
(cond
- (idle-highlight-mode
- (idle-highlight--enable))
- (t
- (idle-highlight--disable))))
+ (idle-highlight-mode
+ (idle-highlight--enable))
+ (t
+ (idle-highlight--disable))))
;;;###autoload
(define-globalized-minor-mode global-idle-highlight-mode
- [nongnu] elpa/idle-highlight-mode updated (5418252a11 -> 215d6612b4), ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode ca1c028daf 04/16: Add melpa link, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 00938d86b4 01/16: Correct URL, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 9976d951f5 07/16: Cleanup: emacs native format,
ELPA Syncer <=
- [nongnu] elpa/idle-highlight-mode f8b3cf0de1 10/16: Update description, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 8ded8426e9 11/16: Release 1.1.4, avoid `global-` prefix for functions and variables, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode d0eb1dc453 15/16: Cleanup: reformat with updated elisp-autofmt, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 215d6612b4 16/16: Cleanup: disable formatting for quoted text, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode e654412df7 06/16: Cleanup: format, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 0a712722c9 03/16: Cleanup: use plist-dolist, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 37e181903c 09/16: Cleanup: add fill-column local variable, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode ae5e663dda 08/16: Cleanup: formatting, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 6749314b0d 13/16: Fix compatibility for pos-bol/eol for emacs <29.1, ELPA Syncer, 2023/02/07
- [nongnu] elpa/idle-highlight-mode 6f3a6252e9 02/16: Resolve issues building the packages with elpa.gnu.org, ELPA Syncer, 2023/02/07