[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-hydra f9fa30d 211/395: More compatibility fixes
From: |
Basil L. Contovounesios |
Subject: |
[elpa] externals/ivy-hydra f9fa30d 211/395: More compatibility fixes |
Date: |
Thu, 25 Feb 2021 08:32:04 -0500 (EST) |
branch: externals/ivy-hydra
commit f9fa30dbe3413579f26d80110712ac6197355368
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Oleh Krehel <ohwoeowho@gmail.com>
More compatibility fixes
* counsel.el: Require subr-x.el which was added in Emacs 24.4.
(counsel--string-trim-left): Remove unneeded duplicate of
string-trim-left.
(counsel-M-x-action): Replace counsel--string-trim-left with simpler
string-remove-prefix.
(counsel-recentf-include-xdg-list): Fix URL hyperlink.
(counsel--strip-prefix): Remove unneeded duplicate of
ivy--remove-prefix.
(counsel--xml-parse-region): New compatibility shim for
libxml-parse-xml-region which falls back to using xml-parse-region
when libxml2 is not available.
(counsel--recentf-get-xdg-recent-files): Use it. Replace
counsel--strip-prefix with string-remove-prefix. Assume every
bookmark node has a href attribute, as mandated by the spec. Fix
decoding of file names that include newlines. Allow
decode-coding-string to return its argument unchanged. Simplify
using cl-mapcan. Improve error reporting and docstring.
* ivy.el (ivy--remove-prefix): Remove unneeded duplicate of
string-remove-prefix and change all callers to use the latter.
Fixes #2527
Fixes #2528
---
counsel.el | 104 +++++++++++++++++++++++++++++----------------------------
ivy-overlay.el | 6 ++--
ivy.el | 20 +++++------
3 files changed, 66 insertions(+), 64 deletions(-)
diff --git a/counsel.el b/counsel.el
index ee8e92a..a5e9b66 100644
--- a/counsel.el
+++ b/counsel.el
@@ -41,9 +41,13 @@
;;; Code:
(require 'swiper)
+
(require 'compile)
(require 'dired)
+(eval-when-compile
+ (require 'subr-x))
+
(defgroup counsel nil
"Completion functions using Ivy."
:group 'matching
@@ -885,17 +889,9 @@ packages are, in order of precedence, `amx' and `smex'."
(defvar counsel-M-x-history nil
"History for `counsel-M-x'.")
-(defsubst counsel--string-trim-left (string &optional regexp)
- "Trim STRING of leading string matching REGEXP.
-
-REGEXP defaults to \"[ \\t\\n\\r]+\"."
- (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)") string)
- (replace-match "" t t string)
- string))
-
(defun counsel-M-x-action (cmd)
"Execute CMD."
- (setq cmd (intern (counsel--string-trim-left cmd "\\^")))
+ (setq cmd (intern (string-remove-prefix "^" cmd)))
(cond ((bound-and-true-p amx-initialized)
(amx-rank cmd))
((bound-and-true-p smex-initialized-p)
@@ -2233,9 +2229,12 @@ When INITIAL-INPUT is non-nil, use it in the minibuffer
during completion."
(declare-function recentf-mode "recentf")
(defcustom counsel-recentf-include-xdg-list nil
- "Include recently used files listed by XDG-compliant environments, e.g.
GNOME and KDE.
-https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec/."
- :type 'boolean)
+ "Include recently used files listed by XDG-compliant environments.
+Examples of such environments are GNOME and KDE. See the URL
+`https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec'."
+ :type 'boolean
+ :link '(url-link "\
+https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec"))
;;;###autoload
(defun counsel-recentf ()
@@ -2249,6 +2248,7 @@
https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec/."
(find-file f)))
:require-match t
:caller 'counsel-recentf))
+
(ivy-set-actions
'counsel-recentf
'(("j" find-file-other-window "other window")
@@ -2282,49 +2282,51 @@ time."
(file-attributes file1))))))))
(mapcar #'substring-no-properties recentf-list)))
-(defun counsel--strip-prefix (prefix str)
- "Strip PREFIX from STR."
- (let ((l (length prefix)))
- (when (string= (substring str 0 l) prefix)
- (substring str l))))
-
-(declare-function dom-attr "dom")
-(declare-function dom-by-tag "dom")
+(defalias 'counsel--xml-parse-region
+ (if (cond ((fboundp 'libxml-available-p)
+ ;; Added in Emacs 27.1.
+ (libxml-available-p))
+ ((fboundp 'libxml-parse-xml-region)
+ ;; Checking for `fboundp' is not enough on Windows, where it
+ ;; will return non-nil even if the library is not installed.
+ (with-temp-buffer
+ (insert "<xml/>")
+ (libxml-parse-xml-region (point-min) (point-max)))))
+ (lambda (&optional beg end)
+ (libxml-parse-xml-region (or beg (point-min)) (or end (point-max))))
+ #'xml-parse-region)
+ "Compatibility shim for `libxml-parse-xml-region'.
+For convenience, BEG and END default to `point-min' and
+`point-max', respectively.
+
+\(fn &optional BEG END)")
(defun counsel--recentf-get-xdg-recent-files ()
-
- "Get recent files as listed by XDG compliant programs.
-
-Requires Emacs 25.
-
-It searches for the file \"recently-used.xbel\" which lists files
-and directories, in the directory returned by the function
-`xdg-data-home'. This file is processed using functionality
-provided by the libxml2 bindings and the \"dom\" library."
- (require 'dom)
+ "Return list of XDG recent files.
+
+This information is parsed from the file \"recently-used.xbel\",
+which lists both files and directories, under `xdg-data-home'.
+This function uses the `dom' library from Emacs 25.1 or later."
+ (unless (require 'dom nil t)
+ (user-error "This function requires Emacs 25.1 or later"))
+ (declare-function dom-attr "dom" (node attr))
+ (declare-function dom-by-tag "dom" (dom tag))
(let ((file-of-recent-files
(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
- nil
- (mapcar
- (lambda (bookmark-node)
- (let ((local-path
- (counsel--strip-prefix
- "file://" (dom-attr bookmark-node 'href))))
- (when local-path
- (let ((full-file-name
- (decode-coding-string
- (url-unhex-string local-path)
- 'utf-8)))
- (when (file-exists-p full-file-name)
- full-file-name)))))
- (nreverse (dom-by-tag (with-temp-buffer
- (insert-file-contents file-of-recent-files)
- (libxml-parse-xml-region (point-min)
- (point-max)))
- 'bookmark)))))))
+ (unless (file-readable-p file-of-recent-files)
+ (user-error "List of XDG recent files not found: %s"
+ file-of-recent-files))
+ (cl-mapcan (lambda (bookmark-node)
+ (let* ((file (dom-attr bookmark-node 'href))
+ (file (string-remove-prefix "file://" file))
+ (file (url-unhex-string file t))
+ (file (decode-coding-string file 'utf-8 t)))
+ (and (file-exists-p file)
+ (list file))))
+ (let ((dom (with-temp-buffer
+ (insert-file-contents file-of-recent-files)
+ (counsel--xml-parse-region))))
+ (nreverse (dom-by-tag dom 'bookmark))))))
(defun counsel-buffer-or-recentf-candidates ()
"Return candidates for `counsel-buffer-or-recentf'."
diff --git a/ivy-overlay.el b/ivy-overlay.el
index 9f863fb..ed77fc0 100644
--- a/ivy-overlay.el
+++ b/ivy-overlay.el
@@ -26,6 +26,9 @@
;;; Code:
+(eval-when-compile
+ (require 'subr-x))
+
(defface ivy-cursor
'((((class color) (background light))
:background "black" :foreground "white")
@@ -93,7 +96,6 @@ Then attach the overlay to the character before point."
(declare-function ivy--get-window "ivy")
(declare-function ivy-state-current "ivy")
(declare-function ivy-state-window "ivy")
-(declare-function ivy--remove-prefix "ivy")
(defun ivy-overlay-impossible-p (_str)
(or
@@ -131,7 +133,7 @@ Hide the minibuffer contents and cursor."
(and (> (length str) 0)
(list "\n"
(ivy-left-pad
- (ivy--remove-prefix "\n" str)
+ (string-remove-prefix "\n" str)
(+
(if (and (eq major-mode 'org-mode)
(bound-and-true-p org-indent-mode))
diff --git a/ivy.el b/ivy.el
index 7d980d9..5149b77 100644
--- a/ivy.el
+++ b/ivy.el
@@ -38,11 +38,15 @@
;;; Code:
-(require 'cl-lib)
-(require 'ivy-overlay)
(require 'colir)
+(require 'ivy-overlay)
+
+(require 'cl-lib)
(require 'ring)
+(eval-when-compile
+ (require 'subr-x))
+
;;* Customization
(defgroup ivy nil
"Incremental vertical completion."
@@ -1176,12 +1180,6 @@ If the text hasn't changed as a result, forward to
`ivy-alt-done'."
(eq ivy--length 1))
(ivy-alt-done))))))
-(defun ivy--remove-prefix (prefix string)
- "Compatibility shim for `string-remove-prefix'."
- (if (string-prefix-p prefix string)
- (substring string (length prefix))
- string))
-
(defun ivy--partial-cd-for-single-directory ()
(when (and
(eq (ivy-state-collection ivy-last) #'read-file-name-internal)
@@ -1199,7 +1197,7 @@ If the text hasn't changed as a result, forward to
`ivy-alt-done'."
(postfix (car tail))
(case-fold-search (ivy--case-fold-p ivy-text))
(completion-ignore-case case-fold-search)
- (new (try-completion (ivy--remove-prefix "^" postfix)
+ (new (try-completion (string-remove-prefix "^" postfix)
(if (ivy-state-dynamic-collection ivy-last)
ivy--all-candidates
(mapcar (lambda (str)
@@ -3755,7 +3753,7 @@ CANDS are the current candidates."
(and (> (length cands) 10000) (eq func
#'ivy-recompute-index-zero)))
0
(or
- (cl-position (ivy--remove-prefix "^" re-str)
+ (cl-position (string-remove-prefix "^" re-str)
cands
:test #'ivy--case-fold-string=)
(and ivy--directory
@@ -4018,7 +4016,7 @@ It has it by default, but the current theme also needs to
set it."
"Highlight STR, using the fuzzy method."
(if (and ivy--flx-featurep
(eq (ivy-alist-setting ivy-re-builders-alist) 'ivy--regex-fuzzy))
- (let ((flx-name (ivy--remove-prefix "^" ivy-text)))
+ (let ((flx-name (string-remove-prefix "^" ivy-text)))
(ivy--flx-propertize
(cons (flx-score str flx-name ivy--flx-cache) str)))
(ivy--highlight-default str)))
- [elpa] externals/ivy-hydra 7084d60 154/395: counsel.el (counsel-cd): Default to the directory of the current buffer, (continued)
- [elpa] externals/ivy-hydra 7084d60 154/395: counsel.el (counsel-cd): Default to the directory of the current buffer, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra fcf5dcf 159/395: ivy.el (ivy--compute-extra-actions): Use the provided doc for "o", Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra e7cc776 174/395: swiper.el (swiper-verbose): New defcustom, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 2894f11 177/395: ivy.el (magic-slash): comment out windows behaviour, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 742119a 181/395: counsel.el (counsel-tracker): New command, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 9ccd93b 191/395: ivy-hydra.el (ivy-hydra-read-action): Work for "C-M-o", Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra bba92e0 188/395: counsel.el (counsel-file-name-filter-alist): Modify perl entry, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 64f05f4 189/395: swiper.el (swiper-font-lock-exclude): Add sieve-mode, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 6f04865 185/395: ivy.el (ivy-init-fns-alist): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1b426e1 202/395: Fix byte-compilation warning in Emacs 28, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra f9fa30d 211/395: More compatibility fixes,
Basil L. Contovounesios <=
- [elpa] externals/ivy-hydra 48e56da 305/395: Extend :type of counsel-async-command-delay, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 0eebf24 318/395: ivy.el (ivy--partial-cd-for-single-directory): Fix for ignore-order, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra edefba7 304/395: ivy-test.el (ivy-read-alist-multi-cands): Add test, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra aa47396 218/395: counsel.el (counsel-fonts): Preselect the current font, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 2bf7317 235/395: ivy.el: ivy--index should never be nil, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 33fa992 250/395: Fix swiper handling of bol regex, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 6ab24b6 249/395: * ivy.el: Use with-eval-after-load, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra ffa5a5f 258/395: counsel-describe-symbol: autoload, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 71f5727 261/395: counsel.el (counsel--git-grep-index): Don't error on null buffer-file-name, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 84efa3a 262/395: Ensure counsel--git-grep-index returns non-nil, Basil L. Contovounesios, 2021/02/25