Skip to content

Commit

Permalink
Simplify debugging and fix dynamic-scoping `eval'
Browse files Browse the repository at this point in the history
* xcb-types.el (xcb:debug): New global minor mode to replace
`xcb:debug-on' and `xcb:debug-toggle'.
(xcb:-log): Use it.

* xcb-types.el (xcb:deftypealias): Use lexical-scoping `eval'.
  • Loading branch information
monnier authored and ch11ng committed Sep 16, 2018
1 parent b700406 commit b8f168b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
20 changes: 7 additions & 13 deletions xcb-types.el
Expand Up @@ -53,25 +53,17 @@
(require 'eieio)
(require 'xcb-debug)

(defvar xcb:debug-on nil "Non-nil to turn on debug.")

(defun xcb:debug-toggle (&optional arg)
"Toggle XELB debugging output.
When ARG is positive, turn debugging on; when negative off. When
ARG is nil, toggle debugging output."
(interactive
(list (or current-prefix-arg 'toggle)))
(setq xcb:debug-on (if (eq arg 'toggle)
(not xcb:debug-on)
(> 0 arg))))
(define-minor-mode xcb:debug
"Debug-logging enabled if non-nil"
:global t)

(defmacro xcb:-log (&optional format-string &rest objects)
"Emit a message prepending the name of the function being executed.
FORMAT-STRING is a string specifying the message to output, as in
`format'. The OBJECTS arguments specify the substitutions."
(unless format-string (setq format-string ""))
`(when xcb:debug-on
`(when xcb:debug
(xcb-debug:message ,(concat "%s:\t" format-string "\n")
(xcb-debug:compile-time-function-name)
,@objects)
Expand Down Expand Up @@ -421,7 +413,9 @@ FORMAT-STRING is a string specifying the message to output, as in
(defmacro xcb:deftypealias (new-type old-type)
"Define NEW-TYPE as an alias of type OLD-TYPE."
`(progn
(cl-deftype ,(eval new-type) nil ,old-type)
;; FIXME: `new-type' should probably just not be eval'd at all,
;; but that requires changing all callers not to quote their arg.
(cl-deftype ,(eval new-type t) nil ,old-type)
(defvaralias ,new-type ,old-type)))

;; 1/2/4 B signed/unsigned integer
Expand Down
4 changes: 0 additions & 4 deletions xcb.el
Expand Up @@ -44,10 +44,6 @@
;; - `xcb:generate-id'
;; Please refer to their documentations for more details.

;; If you ever encountered errors when using this library, please set
;; `xcb:debug-on' to `t' before loading it; this should provide you more clues
;; on what is going wrong.

;; Todo:
;; + Use XC-MISC extension for `xcb:generate-id' when IDs are used up.

Expand Down

0 comments on commit b8f168b

Please sign in to comment.