Commit | Line | Data |
---|---|---|
131e4695 | 1 | ;;; subr-x.el --- extra Lisp functions -*- lexical-binding:t -*- |
7b530552 BB |
2 | |
3 | ;; Copyright (C) 2013 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Maintainer: FSF | |
6 | ;; Keywords: convenience | |
7 | ;; Package: emacs | |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation, either version 3 of the License, or | |
14 | ;; (at your option) any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ||
131e4695 BB |
26 | ;; Less commonly used functions that complement basic APIs, often implemented in |
27 | ;; C code (like hash-tables and strings), and are not eligible for inclusion | |
28 | ;; in subr.el. | |
29 | ||
7b530552 BB |
30 | ;;; Code: |
31 | ||
32 | (defsubst hash-table-keys (hash-table) | |
33 | "Return a list of keys in HASH-TABLE." | |
34 | (let ((keys '())) | |
1d01ad41 | 35 | (maphash (lambda (k _v) (push k keys)) hash-table) |
7b530552 BB |
36 | keys)) |
37 | ||
38 | (defsubst hash-table-values (hash-table) | |
39 | "Return a list of values in HASH-TABLE." | |
40 | (let ((values '())) | |
1d01ad41 | 41 | (maphash (lambda (_k v) (push v values)) hash-table) |
7b530552 BB |
42 | values)) |
43 | ||
015b3b3e BB |
44 | (defsubst string-empty-p (string) |
45 | "Check whether STRING is empty." | |
46 | (string= string "")) | |
47 | ||
4301875e BB |
48 | (defsubst string-join (strings &optional separator) |
49 | "Join all STRINGS using SEPARATOR." | |
50 | (mapconcat 'identity strings separator)) | |
51 | ||
447bdcb8 BB |
52 | (defsubst string-reverse (str) |
53 | "Reverse the string STR." | |
54 | (apply 'string (nreverse (string-to-list str)))) | |
55 | ||
b55aea38 BB |
56 | (defsubst string-trim-left (string) |
57 | "Remove leading whitespace from STRING." | |
58 | (if (string-match "\\`[ \t\n\r]+" string) | |
59 | (replace-match "" t t string) | |
60 | string)) | |
61 | ||
62 | (defsubst string-trim-right (string) | |
63 | "Remove trailing whitespace from STRING." | |
64 | (if (string-match "[ \t\n\r]+\\'" string) | |
65 | (replace-match "" t t string) | |
66 | string)) | |
67 | ||
68 | (defsubst string-trim (string) | |
69 | "Remove leading and trailing whitespace from STRING." | |
70 | (string-trim-left (string-trim-right string))) | |
71 | ||
015b3b3e BB |
72 | (defsubst string-blank-p (string) |
73 | "Check whether STRING is either empty or only whitespace." | |
73c8ceea | 74 | (string-match-p "\\`[ \t\n\r]*\\'" string)) |
015b3b3e | 75 | |
131e4695 | 76 | (provide 'subr-x) |
7b530552 | 77 | |
131e4695 | 78 | ;;; subr-x.el ends here |