/
ce-macros.el
82 lines (66 loc) · 2.17 KB
/
ce-macros.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
75
76
77
78
79
80
81
82
;;; ce-macros.el --- Macros for ce
;;; Commentary:
;;
;; This file defines some useful Emacs Lisp macros for the ce-el project.
;;; Code:
(eval-when-compile
(require 'cl))
(defmacro at-least-two (list)
"Quickly determine whether LIST has at least two members."
`(and ,list (cdr ,list)))
(defmacro stringify (symbol-or-string)
"Given SYMBOL-OR-STRING, return a string representation."
`(if (stringp ,symbol-or-string)
,symbol-or-string
(symbol-name ,symbol-or-string)))
(defmacro symbolify (symbol-or-string)
"Return a symbolic representation of SYMBOL-OR-STRING."
`(if (symbolp ,symbol-or-string)
,symbol-or-string
(make-symbol ,symbol-or-string)))
(defmacro beg-of-buffer ()
"Go to the beginning of the buffer.
The Emacs Lisp function BEGINNING-OF-BUFFER can claim the most
perspicuous name, but the Emacs Lisp compiler warns against
using this function. The documentation for
`beginning-of-buffer' (as of Emacs 23.3) gives a hint:
Don't use this command in Lisp programs!
(goto-char (point-min)) is faster.
But writing '(goto-char (point-min))' is the kind of
speaking-in-code that I dislike so much. Whence this macro."
`(goto-char (point-min)))
(defmacro keep-evaluating (&rest body)
(let ((condition-case-forms
(mapcar #'(lambda (form)
(list 'condition-case
'error-var
form
(list 'error
(list 'message
"Something went wrong; the error was:%c%c %s%c"
?\n ?\n (list 'error-message-string 'error-var) ?\n))))
body)))
`(progn
,@condition-case-forms)))
(defmacro ensure-nxml-mode ()
`(progn
(when (not (fboundp 'nxml-mode))
(error "It seems that nxml-mode is not available."))
(when (not (eq major-mode 'nxml-mode))
(nxml-mode))))
(defmacro foreach-xml-token (&rest body)
`(save-excursion
(goto-char (point-min))
(let* ((begin (point))
(current-xml-token (xmltok-forward))
(end (point)))
(while current-xml-token
,@body
(setf begin end
current-xml-token (xmltok-forward)
end (point))))))
(provide 'ce-macros)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions)
;; End:
;;; ce-macros.el ends here