slides: http://rocky.github.io/NYC-Elisp-talk
text: https://github.com/rocky/rocky.github.io/wiki/NYC-Elisp-talk
A full answer would be long. Here I want to focus on:
In my opinion
Please don't get unnecessarily creative.
Lisp_Object buffer-live-p(Lisp_Object object) { ...
add_docstring("non nil if buffer OBJECT ...");
...
we have:
DEFUN("buffer-live-p", ... 1, 1, 0, doc: /* non-nil if buffer OBJECT has not been killed... */)
(Lisp_Object object)
{
return ((BUFFERP (object) && ! NILP (BVAR (XBUFFER (object), name)))
? Qt : Qnil);
}
Macro enforces remembering the doc string
return ((BUFFERP (object) && ! NILP (BVAR (XBUFFER (object), name)))
? Qt : Qnil);
is roughly in Emacs Lisp:
(if (and (bufferp object) (not (null (BVAR object name))))
t
nil)
which could be shortened if C were more Lisp-like:
(and (bufferp object) (BVAR object name))
DEFUN ("buffer-list", Fbuffer_list, Sbuffer_list, 0, 0, 0,
"Return a list of all buffers.")
()
{
return Fmapcar (Qcdr, Vbuffer_alist);
}
and the next function get_buffer after that:
... return Fcdr (Fassoc (name, Vbuffer_alist));
Done this way to be fast?
Show fundamental-mode from simple.el in Emacs 18.59
gud uses a macro to translate its debugger command into a string sent to a real debugger.
For example, for gdb:
(gud-def gud-remove "clear %f:%l" "\C-d" "Remove breakpoint at current line")
expands to:
(progn
(defalias gud-remove
(lambda (arg) '("Remove breakpoint at current line")
(interactive "p")
(if (not gud-running) (gud-call "clear %f:l" arg))))
(local-set-key "\C-c\C-d" 'gud-remove)
(global-set-key (vconcat gud-key-prefix "\C-d") 'gud-remove))
I suspect a macro isn't needed here.
;; Where gud-display-frame should put the debugging arrow; a cons of
;; (filename . line-number). Set by the marker-filter, which scans
;;; the debugger output for indications of the current program counter.
(defvar gud-last-frame nil)
;; Used by gud-refresh, which should cause gud-display-frame to redisplay
;; the last frame, even if it's been called before and gud-last-frame has
;; been set to nil.
(defvar gud-last-last-frame nil)
(defstruct dbgr-loc
"Our own location type. Even though a mark contains a
file-name (via a buffer) and a line number (via an offset), we
want to save the values that were seen/requested originally."
num ;; If there is a number such as a breakpoint or frame
;; number associated with this location, this is set.
;; nil otherwise.
filename
line-number
column-number ;; Column offset within line
marker ;; Position in source code
cmd-marker ;; Position in command process buffer
)
To access a field in dbgr-cmdbuf-info
(defstruct dbgr-cmdbuf-info
bp-list ...
)
we write:
(dbgr-cmdbuf-info-bp-list dbgr-cmdbuf-info)
I have a macro to write instead:
(dbgr-sget 'cmdbuf-info 'bp-list)