branch: externals/ivy-hydra commit f2852fc90b2dfc2b7aaa39381a3849d10adb10f3 Author: Basil L. Contovounesios <conto...@tcd.ie> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Clean up compatibility code counsel.el: Add comments noting Emacs versions required where applicable. (counsel-recentf-candidates): Silence pre-Emacs 26 byte-compiler. (counsel--recentf-get-xdg-recent-files): Use counsel--xdg-data-home compatibility shim. (counsel--imenu-candidates): Simply load built-in library imenu.el. (counsel--minor-candidates): Avoid using alist-get which was added in Emacs 25.1. (counsel-mode): Assume nadvice.el functions are defined now that Counsel requires Emacs 24.5 or later. ivy-test.el (require-features): Rename as... (ivy-features): ...this, using an appropriate package prefix. All users changed. (ivy-tests-require-hook): Convert obsolete defadvice... (ivy-test--record-feature): ...to this :after-while advice which populates ivy-features only if 'require' succeeded and while avoiding duplicate elements. (no-void-function): Remove unneeded defadvice now that Ivy requires Emacs 24.5 or later. (ivy-partial-2): Assume read--expression is defined now that Ivy requires Emacs 24.5 or later. ivy.el: Add comments noting Emacs versions required where applicable. (ivy-display-style): Default to 'fancy' now that Ivy requires Emacs 24.5 or later. (defvar-local, setq-local): Don't define now that Ivy requires Emacs 24.5 or later. (ivy--compute-extra-actions): Avoid using assoc-delete-all which was added in Emacs 27.1 (ivy--avy-handler-function): Don't write characters as numbers. (ivy--file-local-name): New compatibility shim for Emacs 26.1 function file-local-name. (ivy--magic-tilde-directory): Use it. (ivy-add-face-text-property): Remove compatibility shim now that Ivy requires Emacs 24.5 or later. All callers changed to call add-face-text-property directly. (ivy-yank-symbol): Assume forward-symbol is always defined now that Ivy requires Emacs 24.5 or later. swiper.el: Add comments noting Emacs versions required where applicable. Fixes #2523 --- counsel.el | 33 +++++++++++++----------- ivy-overlay.el | 9 +++---- ivy-test.el | 45 +++++++++++++-------------------- ivy.el | 80 +++++++++++++++++++--------------------------------------- swiper.el | 8 +++--- 5 files changed, 69 insertions(+), 106 deletions(-) diff --git a/counsel.el b/counsel.el index 25c0d4b..e6657f7 100644 --- a/counsel.el +++ b/counsel.el @@ -485,6 +485,7 @@ Used by commands `counsel-describe-variable' and (declare-function xref-push-marker-stack "xref") (defalias 'counsel--push-xref-marker + ;; Added in Emacs 25.1. (if (require 'xref nil t) #'xref-push-marker-stack (require 'etags) @@ -618,6 +619,8 @@ to `ivy-highlight-face'." (sym-value (symbol-value sym)) (expr (minibuffer-with-setup-hook (lambda () + ;; Functions `elisp-eldoc-documentation-function' and + ;; `elisp-completion-at-point' added in Emacs 25.1. (add-function :before-until (local 'eldoc-documentation-function) #'elisp-eldoc-documentation-function) (add-hook 'completion-at-point-functions #'elisp-completion-at-point nil t) @@ -1410,12 +1413,10 @@ This function should set `ivy--old-re'." (defun counsel-git-grep-transformer (str) "Highlight file and line number in STR." (when (string-match "\\`\\([^:]+\\):\\([^:]+\\):" str) - (ivy-add-face-text-property (match-beginning 1) (match-end 1) - 'ivy-grep-info - str) - (ivy-add-face-text-property (match-beginning 2) (match-end 2) - 'ivy-grep-line-number - str)) + (add-face-text-property (match-beginning 1) (match-end 1) + 'ivy-grep-info nil str) + (add-face-text-property (match-beginning 2) (match-end 2) + 'ivy-grep-line-number nil str)) str) (defvar counsel-git-grep-projects-alist nil @@ -2263,7 +2264,8 @@ When `counsel-recentf-include-xdg-list' is non-nil, also include the files in said list, sorting the combined list by file access time." (if (and counsel-recentf-include-xdg-list - (version< "25" emacs-version)) + (>= emacs-major-version 26)) + (declare-function file-attribute-access-time "files" (attributes)) (delete-dups (sort (append (mapcar #'substring-no-properties recentf-list) (counsel--recentf-get-xdg-recent-files)) @@ -2298,7 +2300,7 @@ and directories, in the directory returned by the function provided by the libxml2 bindings and the \"dom\" library." (require 'dom) (let ((file-of-recent-files - (expand-file-name "recently-used.xbel" (xdg-data-home)))) + (expand-file-name "recently-used.xbel" (counsel--xdg-data-home)))) (if (not (file-readable-p file-of-recent-files)) (user-error "List of XDG recent files not found.") (delq @@ -3673,6 +3675,7 @@ version. Argument values are based on the counsel-org-headline-display-todo counsel-org-headline-display-priority counsel-org-headline-display-comment)) + ;; Added in Emacs 26.1. (if (if (fboundp 'func-arity) (< (cdr (func-arity #'org-get-heading)) 3) (version< org-version "9.1.1")) @@ -4507,8 +4510,7 @@ S will be of the form \"[register]: content\"." (declare-function imenu--make-index-alist "imenu") (defun counsel--imenu-candidates () - (unless (featurep 'imenu) - (require 'imenu nil t)) + (require 'imenu) (let* ((imenu-auto-rescan t) (imenu-auto-rescan-maxout (if current-prefix-arg (buffer-size) @@ -5686,6 +5688,8 @@ counter value and iteration amount." :caller 'counsel-rhythmbox)) ;;** `counsel-linux-app' + +;; Added in Emacs 26.1. (require 'xdg nil t) (defalias 'counsel--xdg-data-home @@ -5835,6 +5839,7 @@ This function always returns its elements in a stable order." (dolist (dir counsel-linux-apps-directories) (when (file-exists-p dir) (let ((dir (file-name-as-directory dir))) + ;; Function `directory-files-recursively' added in Emacs 25.1. (dolist (file (directory-files-recursively dir ".*\\.desktop$")) (let ((id (subst-char-in-string ?/ ?- (file-relative-name file dir)))) (when (and (not (gethash id hash)) (file-readable-p file)) @@ -6437,7 +6442,7 @@ and minor mode symbol." (mapcar (lambda (mode) (when (and (boundp mode) (commandp mode)) - (let ((lighter (alist-get mode minor-mode-alist))) + (let ((lighter (cdr (assq mode minor-mode-alist)))) (cons (concat (if (symbol-value mode) "-" "+") (symbol-name mode) @@ -6697,13 +6702,11 @@ Local bindings (`counsel-mode-map'): :lighter " counsel" (if counsel-mode (progn - (when (and (fboundp 'advice-add) - counsel-mode-override-describe-bindings) + (when counsel-mode-override-describe-bindings (advice-add #'describe-bindings :override #'counsel-descbinds)) (define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)) - (when (fboundp 'advice-remove) - (advice-remove #'describe-bindings #'counsel-descbinds)))) + (advice-remove #'describe-bindings #'counsel-descbinds))) (provide 'counsel) diff --git a/ivy-overlay.el b/ivy-overlay.el index 9c7ff84..9f863fb 100644 --- a/ivy-overlay.el +++ b/ivy-overlay.el @@ -90,7 +90,6 @@ Then attach the overlay to the character before point." (defvar ivy-last) (defvar ivy-text) (defvar ivy-completion-beg) -(declare-function ivy-add-face-text-property "ivy") (declare-function ivy--get-window "ivy") (declare-function ivy-state-current "ivy") (declare-function ivy-state-window "ivy") @@ -115,8 +114,8 @@ Hide the minibuffer contents and cursor." (save-excursion (forward-line 1) (insert str))) - (ivy-add-face-text-property (minibuffer-prompt-end) (point-max) - '(:foreground "white")) + (add-face-text-property (minibuffer-prompt-end) (point-max) + '(:foreground "white")) (setq cursor-type nil) (with-selected-window (ivy--get-window ivy-last) (when cursor-type @@ -145,8 +144,8 @@ Hide the minibuffer contents and cursor." (goto-char ivy-completion-beg)) (current-column))))))))) (let ((cursor-offset (1+ (length ivy-text)))) - (ivy-add-face-text-property cursor-offset (1+ cursor-offset) - 'ivy-cursor overlay-str t)) + (add-face-text-property cursor-offset (1+ cursor-offset) + 'ivy-cursor t overlay-str)) (ivy-overlay-show-after overlay-str))))) (provide 'ivy-overlay) diff --git a/ivy-test.el b/ivy-test.el index 1ab10bd..92b57c3 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -26,32 +26,37 @@ ;;; Code: -(defvar require-features nil) (defvar ivy-empty "tests/find-file/empty-dir/") -(defadvice require (before ivy-tests-require-hook (feature &rest _) activate) - "Record the requires into `require-features'." - (push feature require-features)) +(defvar ivy-features nil + "Like `features' but for Ivy testing purposes.") -(require 'ert) -(require 'colir) +(defun ivy-test--record-feature (feature &rest _) + "Record FEATURE in `ivy-features'. +Intended as :after-while advice for `require'." + (add-to-list 'ivy-features feature nil #'eq)) + +(advice-add 'require :after-while #'ivy-test--record-feature) ;; Useful for #'ivy-read-remap. It must arrive before (require 'ivy). (define-key global-map (kbd "<S-right>") #'end-of-buffer) -(require 'ivy) +(require 'colir) (require 'counsel) +(require 'ivy) + +(require 'ert) (message "%s" (emacs-version)) (setq ivy-last (make-ivy-state)) (ert-deftest ivy--lazy-load-ffap--ffap-url-p () - (should (not (memq 'ffap require-features))) + (should (not (memq 'ffap ivy-features))) (should (not (fboundp 'ffap-url-p))) (should (string= (ivy-ffap-url-p "https://foo.org") "https://foo.org")) - (should (memq 'ffap require-features)) + (should (memq 'ffap ivy-features)) (should (fboundp 'ffap-url-p))) (defvar ivy-expr nil @@ -96,18 +101,6 @@ Since `execute-kbd-macro' doesn't pick up a let-bound `default-directory'.") (setq this-command cmd) (apply #'command-execute cmd args)) -(defadvice symbol-function (around no-void-function activate) - "Suppress void-function errors. - -This advice makes `symbol-function' return nil when called on a -symbol with no function rather than throwing a void-function -error. On Emacs 24.4 and above, this has no effect, because -`symbol-function' already does this, but on 24.3 and earlier, it -will bring the behavior in line with the newer Emacsen." - (condition-case nil - ad-do-it - (void-function nil))) - (ert-deftest ivy-partial-1 () (should (equal (ivy-with '(ivy-read "test: " '("case" "Case")) @@ -336,13 +329,9 @@ will bring the behavior in line with the newer Emacsen." (should (equal (ivy--regex-plus "add path\\!") "\\(add\\).*?\\(path!\\)"))) (ert-deftest ivy-partial-2 () - (when (fboundp 'read--expression) - (should - (equal - (ivy-with '(read--expression "Eval: " - "'s-c-t-st") - "<tab> C-m") - '(quote shell-command-to-string))))) + (should (equal (ivy-with '(read--expression "Eval: " "'s-c-t-st") + "<tab> C-m") + '(quote shell-command-to-string)))) (ert-deftest ivy--regex-fuzzy () (should (string= (ivy--regex-fuzzy "tmux") diff --git a/ivy.el b/ivy.el index 343a3b5..7d980d9 100644 --- a/ivy.el +++ b/ivy.el @@ -192,17 +192,13 @@ Set this to \"(%d/%d) \" to display both the index and the count." "When non-nil, wrap around after the first and the last candidate." :type 'boolean) -(defcustom ivy-display-style (and (fboundp 'add-face-text-property) 'fancy) +(defcustom ivy-display-style 'fancy "The style for formatting the minibuffer. By default, the matched strings are copied as is. The fancy display style highlights matching parts of the regexp, -a behavior similar to `swiper'. - -This setting depends on `add-face-text-property' - a C function -available since Emacs 24.4. Fancy style will render poorly in -earlier versions of Emacs." +a behavior similar to `swiper'." :type '(choice (const :tag "Plain" nil) (const :tag "Fancy" fancy))) @@ -328,7 +324,9 @@ ACTIONS that have the same key." :key #'car :test #'equal)) (override-default (assoc "o" extra-actions))) (cond (override-default - (cons 1 (cons override-default (assoc-delete-all "o" extra-actions)))) + (cons 1 (cons override-default + (cl-delete "o" extra-actions + :key #'car :test #'equal)))) ((not extra-actions) action) ((functionp action) @@ -700,18 +698,6 @@ N is obtained from `ivy-more-chars-alist'." "Like `string=', but obeys `case-fold-search'." (eq t (compare-strings s1 nil nil s2 nil nil case-fold-search))) -(eval-and-compile - (unless (fboundp 'defvar-local) - (defmacro defvar-local (var val &optional docstring) - "Define VAR as a buffer-local variable with default value VAL." - (declare (debug defvar) (doc-string 3)) - (list 'progn (list 'defvar var val docstring) - (list 'make-variable-buffer-local (list 'quote var))))) - (unless (fboundp 'setq-local) - (defmacro setq-local (var val) - "Set variable VAR to value VAL in current buffer." - (list 'set (list 'make-local-variable (list 'quote var)) val)))) - (defmacro ivy-quit-and-run (&rest body) "Quit the minibuffer and run BODY afterwards." (declare (indent 0)) @@ -1823,7 +1809,7 @@ This string is inserted into the minibuffer." (defun ivy--avy-handler-function (char) (let (cmd) - (cond ((memq char '(27 ?\C-g)) + (cond ((memq char '(?\C-\[ ?\C-g)) ;; exit silently (throw 'done 'abort)) ((memq (setq cmd (lookup-key ivy-minibuffer-map (vector char))) @@ -2074,6 +2060,7 @@ An :init is a function with no arguments. :type 'integer) (defalias 'ivy--dirname-p + ;; Added in Emacs 25.1. (if (fboundp 'directory-name-p) #'directory-name-p (lambda (name) @@ -3195,7 +3182,7 @@ parts beyond their respective faces `ivy-confirm-face' and ;; remove the face as well. (when ivy--use-selectable-prompt (if (= ivy--index -1) - (ivy-add-face-text-property + (add-face-text-property (minibuffer-prompt-end) (line-end-position) 'ivy-prompt-match) (remove-list-of-text-properties (minibuffer-prompt-end) (line-end-position) '(face)))) @@ -3350,18 +3337,21 @@ Should be run via minibuffer `post-command-hook'." 'ivy--exhibit))) (ivy--exhibit))) -(unless (fboundp 'file-local-name) - (defun file-local-name (file) - "Emacs has this function since 26.1." - (or (file-remote-p file 'localname) file))) +(defalias 'ivy--file-local-name + (if (fboundp 'file-local-name) + #'file-local-name + (lambda (file) + (or (file-remote-p file 'localname) file))) + "Compatibility shim for `file-local-name'. +The function was added in Emacs 26.1.") (defun ivy--magic-tilde-directory (dir) "Return an appropriate home for DIR for when ~ or ~/ are entered." (file-name-as-directory (expand-file-name (let* ((home (expand-file-name (concat (file-remote-p dir) "~/"))) - (dir-path (file-local-name dir)) - (home-path (file-local-name home))) + (dir-path (ivy--file-local-name dir)) + (home-path (ivy--file-local-name home))) (if (string= dir-path home-path) "~" home))))) @@ -3510,8 +3500,8 @@ Should be run via minibuffer `post-command-hook'." (colir-blend-face-background 0 len face str) (let ((foreground (face-foreground face))) (when foreground - (ivy-add-face-text-property - 0 len (list :foreground foreground) str)))) + (add-face-text-property + 0 len (list :foreground foreground) nil str)))) (error (ignore-errors (font-lock-append-text-property 0 len 'face face str))))) @@ -3907,7 +3897,7 @@ N wraps around, but skips the first element of the list." (unless (eq j (1+ last-j)) (cl-incf i)) (setq last-j j) - (ivy-add-face-text-property j (1+ j) (ivy--minibuffer-face i) str)) + (add-face-text-property j (1+ j) (ivy--minibuffer-face i) nil str)) str)) (defun ivy--flx-sort (name cands) @@ -4011,31 +4001,16 @@ It has it by default, but the current theme also needs to set it." cands "")) -(defalias 'ivy-add-face-text-property - (if (fboundp 'add-face-text-property) - (lambda (start end face &optional object append) - (add-face-text-property start end face append object)) - (lambda (start end face &optional object append) - (funcall (if append - #'font-lock-append-text-property - #'font-lock-prepend-text-property) - start end 'face face object))) - "Compatibility shim for `add-face-text-property'. -Fall back on `font-lock-prepend-text-property' in Emacs versions -prior to 24.4 (`font-lock-append-text-property' when APPEND is -non-nil). -Note: The usual last two arguments are flipped for convenience.") - (defun ivy--highlight-ignore-order (str) "Highlight STR, using the ignore-order method." (when (consp ivy--old-re) (let ((i 1)) (dolist (re ivy--old-re) (when (string-match (car re) str) - (ivy-add-face-text-property + (add-face-text-property (match-beginning 0) (match-end 0) (ivy--minibuffer-face i) - str)) + nil str)) (cl-incf i)))) str) @@ -4087,7 +4062,7 @@ in this case." (car ivy-minibuffer-faces)) (t (ivy--minibuffer-face n))))) - (ivy-add-face-text-property beg end face str)) + (add-face-text-property beg end face nil str)) (unless (zerop i) (setq prev end)))) (cl-incf i))))))) @@ -4121,8 +4096,8 @@ in this case." str) (when annot (setq str (concat str (funcall annot str))) - (ivy-add-face-text-property - olen (length str) 'ivy-completions-annotations str)) + (add-face-text-property + olen (length str) 'ivy-completions-annotations nil str)) str)) (defun ivy-read-file-transformer (str) @@ -4578,7 +4553,7 @@ Skip buffers that match `ivy-ignore-buffers'." "Append to STR the property FACE." (when face (setq str (copy-sequence str)) - (ivy-add-face-text-property 0 (length str) face str t)) + (add-face-text-property 0 (length str) face t str)) str) (defun ivy-switch-buffer-transformer (str) @@ -4689,9 +4664,6 @@ words (previous if ARG is negative)." If optional ARG is non-nil, pull in the next ARG symbols (previous if ARG is negative)." (interactive "p") - ;; Emacs < 24.4 compatibility - (unless (fboundp 'forward-symbol) - (require 'thingatpt)) (ivy--yank-by #'forward-symbol (or arg 1))) (defun ivy-yank-char (&optional arg) diff --git a/swiper.el b/swiper.el index f40b8f1..b8b0b7f 100644 --- a/swiper.el +++ b/swiper.el @@ -468,6 +468,7 @@ such as `scroll-conservatively' are set to a high value.") (unless (swiper-font-lock-ensure-p) (unless (or (> (buffer-size) 100000) (null font-lock-mode)) (if (fboundp 'font-lock-ensure) + ;; Added in Emacs 25.1. (font-lock-ensure) (with-no-warnings (font-lock-fontify-buffer)))))) @@ -504,8 +505,6 @@ such as `scroll-conservatively' are set to a high value.") " " (buffer-substring beg end)))) -(declare-function outline-show-all "outline") - (defvar swiper-use-visual-line-p (lambda (n-lines) (and visual-line-mode @@ -527,6 +526,7 @@ numbers; replaces calculating the width from buffer line count." (when (eq major-mode 'org-mode) (require 'outline) (if (fboundp 'outline-show-all) + ;; Added in Emacs 25.1. (outline-show-all) (with-no-warnings (show-all)))) @@ -766,6 +766,7 @@ line numbers. For the buffer, use `ivy--regex' instead." (setq ivy--subexps 1))) (t (format "^ %s" re))))) + ;; Added in Emacs 25.1. ((fboundp (bound-and-true-p search-default-mode)) (if (string-match "\\`\\\\_<\\(.+\\)\\\\_>\\'" str) (concat @@ -1607,8 +1608,7 @@ When not running `swiper-isearch' already, start it." swiper-faces swiper-background-faces) (lambda (beg end face _priority) - (ivy-add-face-text-property - beg end face str))) + (add-face-text-property beg end face nil str))) (cl-incf i))) str))