aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Oteiza2017-09-09 00:46:41 -0400
committerMark Oteiza2017-09-09 00:46:41 -0400
commitbe9bc8e67d6caf6d61fe4f46ac5b640ada16ba95 (patch)
tree4042d8c5def741ddf3397925bfd213f2efba8495
parentce9640845155c1dd9c11e46104f223af7cd4f7fa (diff)
downloademacs-be9bc8e67d6caf6d61fe4f46ac5b640ada16ba95.tar.gz
emacs-be9bc8e67d6caf6d61fe4f46ac5b640ada16ba95.zip
; 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.
-rw-r--r--lisp/xdg.el39
-rw-r--r--test/lisp/xdg-tests.el19
2 files changed, 18 insertions, 40 deletions
diff --git a/lisp/xdg.el b/lisp/xdg.el
index 4b255429db4..c7000219487 100644
--- a/lisp/xdg.el
+++ b/lisp/xdg.el
@@ -143,12 +143,11 @@ This should be called at the beginning of a line."
143 res)) 143 res))
144 144
145(defun xdg-user-dir (name) 145(defun xdg-user-dir (name)
146 "Return the path of user directory referred to by NAME." 146 "Return the directory referred to by NAME."
147 (when (null xdg-user-dirs) 147 (when (null xdg-user-dirs)
148 (save-match-data 148 (setq xdg-user-dirs
149 (setq xdg-user-dirs 149 (xdg--user-dirs-parse-file
150 (xdg--user-dirs-parse-file 150 (expand-file-name "user-dirs.dirs" (xdg-config-home)))))
151 (expand-file-name "user-dirs.dirs" (xdg-config-home))))))
152 (let ((dir (cdr (assoc name xdg-user-dirs)))) 151 (let ((dir (cdr (assoc name xdg-user-dirs))))
153 (when dir (expand-file-name dir)))) 152 (when dir (expand-file-name dir))))
154 153
@@ -182,27 +181,25 @@ This should be called at the beginning of a line."
182 (let ((res (make-hash-table :test #'equal)) 181 (let ((res (make-hash-table :test #'equal))
183 elt group) 182 elt group)
184 (with-temp-buffer 183 (with-temp-buffer
185 (save-match-data 184 (insert-file-contents-literally filename)
186 (insert-file-contents-literally filename) 185 (goto-char (point-min))
187 (goto-char (point-min)) 186 (while (or (= (following-char) ?#)
188 (while (or (= (following-char) ?#) 187 (string-blank-p (buffer-substring (point) (point-at-eol))))
189 (string-blank-p (buffer-substring (point) (point-at-eol)))) 188 (forward-line))
190 (forward-line)) 189 (unless (equal (setq group (xdg--desktop-parse-line)) "Desktop Entry")
191 (unless (equal (setq group (xdg--desktop-parse-line)) "Desktop Entry") 190 (error "Wrong first section: %s" group))
192 (error "Wrong first section: %s" group)) 191 (while (not (eobp))
193 (while (not (eobp)) 192 (when (consp (setq elt (xdg--desktop-parse-line)))
194 (when (consp (setq elt (xdg--desktop-parse-line))) 193 (puthash (car elt) (cdr elt) res))
195 (puthash (car elt) (cdr elt) res)) 194 (forward-line)))
196 (forward-line))))
197 res)) 195 res))
198 196
199(defun xdg-desktop-strings (value) 197(defun xdg-desktop-strings (value)
200 "Partition VALUE into elements delimited by unescaped semicolons." 198 "Partition VALUE into elements delimited by unescaped semicolons."
201 (let (res) 199 (let (res)
202 (save-match-data 200 (setq value (string-trim-left value))
203 (setq value (string-trim-left value)) 201 (dolist (x (split-string (replace-regexp-in-string "\\\\;" "\0" value) ";"))
204 (dolist (x (split-string (replace-regexp-in-string "\\\\;" "\0" value) ";")) 202 (push (replace-regexp-in-string "\0" ";" x) res))
205 (push (replace-regexp-in-string "\0" ";" x) res)))
206 (when (null (string-match-p "[^[:blank:]]" (car res))) (pop res)) 203 (when (null (string-match-p "[^[:blank:]]" (car res))) (pop res))
207 (nreverse res))) 204 (nreverse res)))
208 205
diff --git a/test/lisp/xdg-tests.el b/test/lisp/xdg-tests.el
index e7e122b54ee..59c850b07af 100644
--- a/test/lisp/xdg-tests.el
+++ b/test/lisp/xdg-tests.el
@@ -3,7 +3,6 @@
3;; Copyright (C) 2017 Free Software Foundation, Inc. 3;; Copyright (C) 2017 Free Software Foundation, Inc.
4 4
5;; Maintainer: emacs-devel@gnu.org 5;; Maintainer: emacs-devel@gnu.org
6
7;; Author: Mark Oteiza <mvoteiza@udel.edu> 6;; Author: Mark Oteiza <mvoteiza@udel.edu>
8 7
9;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
@@ -31,24 +30,6 @@
31(defconst xdg-tests-data-dir 30(defconst xdg-tests-data-dir
32 (expand-file-name "test/data/xdg" source-directory)) 31 (expand-file-name "test/data/xdg" source-directory))
33 32
34(ert-deftest xdg-match-data ()
35 "Ensure public functions do not mangle match data."
36 (let ((data '(1 9)))
37 (save-match-data
38 (set-match-data data)
39 (xdg-user-dir "DOCUMENTS")
40 (should (equal (match-data) data))))
41 (let ((data '(2 9)))
42 (save-match-data
43 (set-match-data data)
44 (xdg-desktop-read-file (expand-file-name "test.desktop" xdg-tests-data-dir))
45 (should (equal (match-data) data))))
46 (let ((data '(3 9)))
47 (save-match-data
48 (set-match-data data)
49 (xdg-desktop-strings "a;b")
50 (should (equal (match-data) data)))))
51
52(ert-deftest xdg-desktop-parsing () 33(ert-deftest xdg-desktop-parsing ()
53 "Test `xdg-desktop-read-file' parsing of .desktop files." 34 "Test `xdg-desktop-read-file' parsing of .desktop files."
54 (let ((tab (xdg-desktop-read-file 35 (let ((tab (xdg-desktop-read-file