From be9bc8e67d6caf6d61fe4f46ac5b640ada16ba95 Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Sat, 9 Sep 2017 00:46:41 -0400 Subject: [PATCH] ; 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. --- lisp/xdg.el | 39 ++++++++++++++++++--------------------- test/lisp/xdg-tests.el | 19 ------------------- 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." 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))) 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 @@ ;; Copyright (C) 2017 Free Software Foundation, Inc. ;; Maintainer: emacs-devel@gnu.org - ;; Author: Mark Oteiza ;; 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 -- 2.39.5