-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbvr-utils.el
74 lines (55 loc) · 2.09 KB
/
bvr-utils.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;;; bvr-utils.el --- Random utils (BVR). -*- lexical-binding: t -*-
;; Author: B.V. Raghav
;; Maintainer: B.V. Raghav
;; Version: 0.1
;; Package-Requires: (cl-lib)
;; Homepage: https://github.com/bvraghav/dotelisp.git
;; Keywords: utils,elisp
;; This file is not part of GNU Emacs
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Random utils collected by BVR from all over the place.
;;; Code:
(require 'cl-lib)
(defgroup bvr-utils nil "Propertie of BVR Utils.")
(defun group-p (symbol)
"Whether SYMBOL exists and is a group."
(and (symbolp symbol)
(or (and (get symbol 'custom-loads)
(not (get symbol 'custom-autoload)))
(get symbol 'custom-group))))
(defun read-integer (&rest args)
"Wrapper around built-in `read-number' function to read integer.
The ARGS are forwarded as is to `read-number'.
Inspired by: Emanuel Berg
https://lists.gnu.org/archive/html//help-gnu-emacs/2021-11/msg00186.html"
(cl-loop with sentinel = "9£9dkt,d"
with args = (or args '("Integer: "))
for n = sentinel
then (apply #'read-number args)
until (or (integerp n)
(unless (equal sentinel n)
(message "Please enter an integer.")
(sit-for 1)
nil))
finally (cl-return n)))
(defun camel-to-title-case (txt)
"Convert TXT from `camelCase' to `Title Case'."
(let ((case-fold-search nil))
(capitalize
(replace-regexp-in-string
"\\([A-Z]\\)"
" \\1"
txt
t))))
(provide 'bvr-utils)
;;; bvr-utils.el ends here