]> git.eshelyaron.com Git - emacs.git/commitdiff
Use 'hash-table-contains-p' in a few places
authorStefan Kangas <stefankangas@gmail.com>
Sat, 29 Mar 2025 12:50:21 +0000 (13:50 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 31 Mar 2025 08:38:15 +0000 (10:38 +0200)
This replaces open coded versions of the common idiom
    (not (eq (gethash key table 'missing) 'missing))
with
    (hash-table-contains-p key table)
in files where we can rely on features in Emacs 31.

* lisp/emacs-lisp/map.el (map-contains-key):
* lisp/external-completion.el (external-completion-table):
* lisp/mh-e/mh-utils.el (mh-sub-folders)
(mh-remove-from-sub-folders-cache):
* lisp/net/ange-ftp.el (ange-ftp-hash-entry-exists-p):
* lisp/password-cache.el (password-in-cache-p, password-cache-add):
* lisp/pcmpl-x.el (pcmpl-x-tlmgr-action-options):
* lisp/xdg.el (xdg-mime-apps): Use 'hash-table-contains-p'.

(cherry picked from commit f60fc1287d499e8c93857b1b96e8bd2467b22c8d)

lisp/emacs-lisp/map.el
lisp/external-completion.el
lisp/net/ange-ftp.el
lisp/password-cache.el
lisp/pcmpl-x.el
lisp/xdg.el

index 72ff5e2221db79a09c8f28a2bac6223322e5cb48..deeeec132cf45a52bedb7efc1396712675c6b1f0 100644 (file)
@@ -403,8 +403,7 @@ If MAP is a plist, TESTFN defaults to `eq'."
 
 (cl-defmethod map-contains-key ((map hash-table) key &optional _testfn)
   "Return non-nil if MAP contains KEY, ignoring TESTFN."
-  (let ((v '(nil)))
-    (not (eq v (gethash key map v)))))
+  (hash-table-contains-p key map))
 
 (cl-defgeneric map-some (pred map)
   "Return the first non-nil value from applying PRED to elements of MAP.
index 6f9b450eb4da9df7a85fce98c3c220c0b9e04c3b..a136674e86918bda7673c6fc77135f3d8f664721 100644 (file)
@@ -117,11 +117,10 @@ EXPANDED-PATTERN."
               completion-category-defaults)))
   (let ((cache (make-hash-table :test #'equal)))
     (cl-flet ((lookup-internal (string point)
-                (let* ((key (cons string point))
-                       (probe (gethash key cache 'external--notfound)))
-                  (if (eq probe 'external--notfound)
-                      (puthash key (funcall lookup string point) cache)
-                    probe))))
+                (let ((key (cons string point)))
+                  (if (hash-table-contains-p key cache)
+                      (gethash key cache)
+                    (puthash key (funcall lookup string point) cache)))))
       (lambda (string pred action)
         (pcase action
           (`metadata
index ad1011cb5d8e88d7d7398bbd0495eec91b2624d7..5c9d3d3ebfd2afa622f586874cd8b82a7a80aef1 100644 (file)
@@ -1004,7 +1004,7 @@ or nil meaning don't change it."
 
 (defun ange-ftp-hash-entry-exists-p (key tbl)
   "Return whether there is an association for KEY in table TBL."
-  (and tbl (not (eq (gethash key tbl 'unknown) 'unknown))))
+  (and tbl (hash-table-contains-p key tbl)))
 
 (defun ange-ftp-hash-table-keys (tbl)
   "Return a sorted list of all the active keys in table TBL, as strings."
index 46c04789c00b0a5bb75b284cbda84bb2ed96a758..5701ac7df664a02cc93fb64aa7329f6ff6098c2c 100644 (file)
@@ -82,8 +82,7 @@ regulate cache behavior."
   "Check if KEY is in the cache."
   (and password-cache
        key
-       (not (eq (gethash key password-data 'password-cache-no-data)
-                'password-cache-no-data))))
+       (hash-table-contains-p key password-data)))
 
 (defun password-read (prompt &optional key)
   "Read password, for use with KEY, from user, or from cache if wanted.
@@ -110,8 +109,7 @@ user again."
   "Add password to cache.
 The password is removed by a timer after `password-cache-expiry' seconds."
   (when (and password-cache-expiry
-             (eq (gethash key password-data 'password-cache-no-data)
-                 'password-cache-no-data))
+             (not (hash-table-contains-p key password-data)))
     (run-at-time password-cache-expiry nil
                 #'password-cache-remove
                 key))
index 578e8a362a34d09432bb16d9b458040f73fe45e1..dbd8600a2e741725fca443002f395def7ea036c0 100644 (file)
 
 (defun pcmpl-x-tlmgr-action-options (action)
   "Get the list of long options for ACTION."
-  (if (eq (gethash action pcmpl-x-tlmgr-options-cache 'missing) 'missing)
+  (if (not (hash-table-contains-p action pcmpl-x-tlmgr-options-cache))
       (with-temp-buffer
         (when (zerop
                (call-process pcmpl-x-tlmgr-program nil t nil action "-h"))
index 7f86c8eb8d062624427b849673e0d24c517bd446..5058fb13052c7924a6315c4b2584c942115aac2f 100644 (file)
@@ -384,9 +384,8 @@ Results are cached in `xdg-mime-table'."
         (setq xdg-mime-table nil)))
     (when (null (assoc type xdg-mime-table))
       (push (cons type (make-hash-table :test #'equal)) xdg-mime-table))
-    (if (let ((def (make-symbol "def"))
-              (table (cdr (assoc type xdg-mime-table))))
-          (not (eq (setq files (gethash subtype table def)) def)))
+    (if (let ((table (cdr (assoc type xdg-mime-table))))
+          (hash-table-contains-p subtype table))
         files
       (and files (setq files nil))
       (let ((dirs (mapcar (lambda (dir) (expand-file-name "applications" dir))