Doom Emacs 函数变量后面的感叹号怎么回事?

请问doom emacs的这段代码里的add-hook!应该如何展开呢?我找不到他定义add-hook!的宏,直接在自己的init file里用add-hook!的话会报警。

(defvar last-file-name-handler-alist file-name-handler-alist)
(setq gc-cons-threshold 402653184
  gc-cons-percentage 0.6
  file-name-handler-alist nil)

;; ... your whole emacs config here ...

;; after startup, it is important you reset this to some reasonable default. A large 
;; gc-cons-threshold will cause freezing and stuttering during long-term 
;; interactive use. I find these are nice defaults:
(add-hook! 'emacs-startup-hook
(setq gc-cons-threshold 16777216
    gc-cons-percentage 0.1
    file-name-handler-alist last-file-name-handler-alist))
(add-hook 'emacs-startup-hook
  (lambda ()
    (setq gc-cons-threshold 16777216
          gc-cons-percentage 0.1
          file-name-handler-alist last-file-name-handler-alist)))
1 个赞

谢谢前辈,看来还是要学一学elisp :dizzy_face:

不敢当。另外你也可以查看 emacs-startup-hook 的值来了解最后加的是什么。

!后缀是scheme的惯例,通常是指由!修饰的函数有副作用, 诸如set!。还有1个在scheme中比较常见的的后缀是?, 类似于common lisp或者elisp的p后缀, 诸如characterp, stringp

1.3.5 Naming conventions

By convention, the names of procedures that always return a boolean value usually end in ``?’’. Such procedures are called predicates.

By convention, the names of procedures that store values into previously allocated locations (see section 3.4) usually end in ``!’’. Such procedures are called mutation procedures. By convention, the value returned by a mutation procedure is unspecified.

By convention, ``->’’ appears within the names of procedures that take an object of one type and return an analogous object of another type. For example, list->vector takes a list and returns a vector whose elements are the same as those of the list.

2 个赞