; Fix previous commit
See https://lists.gnu.org/archive/html/emacs-devel/2017-09/msg00101.html * test/lisp/xdg.el: Remove match data tests. * lisp/xdg.el (xdg-user-dir): Fix docstring. Remove save-match-data. (xdg-desktop-read-file, xdg-desktop-strings): Remove save-match-data.
This commit is contained in:
parent
ce96408451
commit
be9bc8e67d
2 changed files with 18 additions and 40 deletions
39
lisp/xdg.el
39
lisp/xdg.el
|
@ -143,12 +143,11 @@ This should be called at the beginning of a line."
|
|||
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))))
|
||||
|
||||
|
@ -182,27 +181,25 @@ This should be called at the beginning of a line."
|
|||
(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)))
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
;; 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.
|
||||
|
@ -31,24 +30,6 @@
|
|||
(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
|
||||
|
|
Loading…
Add table
Reference in a new issue