branch: externals/ivy-hydra
commit 51fe2ce0ae118e378cebfc5e8d6c4f46bf048def
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel--recentf-get-xdg-recent-files): Decode utf-8
Re #2403
---
counsel.el | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/counsel.el b/counsel.el
index 2616b71..fa1afd4 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2254,6 +2254,14 @@
https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec/."
(version< "25" emacs-version)
(counsel--recentf-get-xdg-recent-files))))
+(defun counsel--strip-prefix (prefix 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")
+
(defun counsel--recentf-get-xdg-recent-files ()
"Get recent files as listed by XDG compliant programs.
@@ -2273,11 +2281,16 @@ provided by the libxml2 bindings and the \"dom\"
library."
nil
(mapcar
(lambda (bookmark-node)
- (let ((full-file-name (url-unhex-string
- (substring (dom-attr bookmark-node 'href)
- 7)))) ; Strip "file://"
- (when (file-exists-p full-file-name)
- full-file-name)))
+ (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)