Update copyright year to 2015
[emacs.git] / lisp / emacs-lisp / subr-x.el
blobf5083c4df944c7a4c7a7870b95ade4ebcaa1fa74
1 ;;; subr-x.el --- extra Lisp functions -*- lexical-binding:t -*-
3 ;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: convenience
7 ;; Package: emacs
9 ;; This file is part of GNU Emacs.
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.
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.
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/>.
24 ;;; Commentary:
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.
30 ;; Do not document these functions in the lispref.
31 ;; http://lists.gnu.org/archive/html/emacs-devel/2014-01/msg01006.html
33 ;;; Code:
35 (defsubst hash-table-keys (hash-table)
36 "Return a list of keys in HASH-TABLE."
37 (let ((keys '()))
38 (maphash (lambda (k _v) (push k keys)) hash-table)
39 keys))
41 (defsubst hash-table-values (hash-table)
42 "Return a list of values in HASH-TABLE."
43 (let ((values '()))
44 (maphash (lambda (_k v) (push v values)) hash-table)
45 values))
47 (defsubst string-empty-p (string)
48 "Check whether STRING is empty."
49 (string= string ""))
51 (defsubst string-join (strings &optional separator)
52 "Join all STRINGS using SEPARATOR."
53 (mapconcat 'identity strings separator))
55 (defsubst string-reverse (str)
56 "Reverse the string STR."
57 (apply 'string (nreverse (string-to-list str))))
59 (defsubst string-trim-left (string)
60 "Remove leading whitespace from STRING."
61 (if (string-match "\\`[ \t\n\r]+" string)
62 (replace-match "" t t string)
63 string))
65 (defsubst string-trim-right (string)
66 "Remove trailing whitespace from STRING."
67 (if (string-match "[ \t\n\r]+\\'" string)
68 (replace-match "" t t string)
69 string))
71 (defsubst string-trim (string)
72 "Remove leading and trailing whitespace from STRING."
73 (string-trim-left (string-trim-right string)))
75 (defsubst string-blank-p (string)
76 "Check whether STRING is either empty or only whitespace."
77 (string-match-p "\\`[ \t\n\r]*\\'" string))
79 (defsubst string-remove-prefix (prefix string)
80 "Remove PREFIX from STRING if present."
81 (if (string-prefix-p prefix string)
82 (substring string (length prefix))
83 string))
85 (defsubst string-remove-suffix (suffix string)
86 "Remove SUFFIX from STRING if present."
87 (if (string-suffix-p suffix string)
88 (substring string 0 (- (length string) (length suffix)))
89 string))
91 (provide 'subr-x)
93 ;;; subr-x.el ends here