res))
(defun xdg-user-dir (name)
- "Return the path of user directory referred to by NAME."
+ "Return the directory referred to by NAME."
(when (null xdg-user-dirs)
- (save-match-data
- (setq xdg-user-dirs
- (xdg--user-dirs-parse-file
- (expand-file-name "user-dirs.dirs" (xdg-config-home))))))
+ (setq xdg-user-dirs
+ (xdg--user-dirs-parse-file
+ (expand-file-name "user-dirs.dirs" (xdg-config-home)))))
(let ((dir (cdr (assoc name xdg-user-dirs))))
(when dir (expand-file-name dir))))
(let ((res (make-hash-table :test #'equal))
elt group)
(with-temp-buffer
- (save-match-data
- (insert-file-contents-literally filename)
- (goto-char (point-min))
- (while (or (= (following-char) ?#)
- (string-blank-p (buffer-substring (point) (point-at-eol))))
- (forward-line))
- (unless (equal (setq group (xdg--desktop-parse-line)) "Desktop Entry")
- (error "Wrong first section: %s" group))
- (while (not (eobp))
- (when (consp (setq elt (xdg--desktop-parse-line)))
- (puthash (car elt) (cdr elt) res))
- (forward-line))))
+ (insert-file-contents-literally filename)
+ (goto-char (point-min))
+ (while (or (= (following-char) ?#)
+ (string-blank-p (buffer-substring (point) (point-at-eol))))
+ (forward-line))
+ (unless (equal (setq group (xdg--desktop-parse-line)) "Desktop Entry")
+ (error "Wrong first section: %s" group))
+ (while (not (eobp))
+ (when (consp (setq elt (xdg--desktop-parse-line)))
+ (puthash (car elt) (cdr elt) res))
+ (forward-line)))
res))
(defun xdg-desktop-strings (value)
"Partition VALUE into elements delimited by unescaped semicolons."
(let (res)
- (save-match-data
- (setq value (string-trim-left value))
- (dolist (x (split-string (replace-regexp-in-string "\\\\;" "\0" value) ";"))
- (push (replace-regexp-in-string "\0" ";" x) res)))
+ (setq value (string-trim-left value))
+ (dolist (x (split-string (replace-regexp-in-string "\\\\;" "\0" value) ";"))
+ (push (replace-regexp-in-string "\0" ";" x) res))
(when (null (string-match-p "[^[:blank:]]" (car res))) (pop res))
(nreverse res)))
;; Copyright (C) 2017 Free Software Foundation, Inc.
;; Maintainer: emacs-devel@gnu.org
-
;; Author: Mark Oteiza <mvoteiza@udel.edu>
;; This file is part of GNU Emacs.
(defconst xdg-tests-data-dir
(expand-file-name "test/data/xdg" source-directory))
-(ert-deftest xdg-match-data ()
- "Ensure public functions do not mangle match data."
- (let ((data '(1 9)))
- (save-match-data
- (set-match-data data)
- (xdg-user-dir "DOCUMENTS")
- (should (equal (match-data) data))))
- (let ((data '(2 9)))
- (save-match-data
- (set-match-data data)
- (xdg-desktop-read-file (expand-file-name "test.desktop" xdg-tests-data-dir))
- (should (equal (match-data) data))))
- (let ((data '(3 9)))
- (save-match-data
- (set-match-data data)
- (xdg-desktop-strings "a;b")
- (should (equal (match-data) data)))))
-
(ert-deftest xdg-desktop-parsing ()
"Test `xdg-desktop-read-file' parsing of .desktop files."
(let ((tab (xdg-desktop-read-file