看到的一个比较好的learn emacs from scratch

https://huytd.github.io/emacs-from-scratch.html

reddit上也是好评如潮. https://www.reddit.com/r/emacs/comments/8uwzjx/guide_to_config_emacs_from_scratch/

比较适合像窝这种小白用户(从spacemacs入坑, 现在想出来但是懒得rtfm)

2018-07-14 更新 原文已经改正了下面提到的错误。

;; Minimal UI
(scroll-bar-mode nil)
(tool-bar-mode   nil)
(tooltip-mode    nil)
(menu-bar-mode   nil)

其中关闭 Mode 的代码有问题,我认为比较好的写法是:

;; Turn on
(tool-bar-mode)
;; Turn off
(tool-bar-mode -1)

下面是一些我不喜欢的写法

;; Turn on
(tool-bar-mode 1)                       ; 啰嗦
(tool-bar-mode t)                       ; 啰嗦
(tool-bar-mode nil)                     ; 啰嗦且违反直觉
;; Turn off
(tool-bar-mode 0)
1 个赞

用零的话会不会给初学者一种“0是nil”的感觉

看到这个帖子突然想到一个困惑我的问题,如何才能比较方便的切换emacs的配置文件呢?有时候emacs出了问题,为了确定是否和spacemacs相关,我只好把.spacemacs和.emacs.d全部移动到其他的文件夹里面,用原来的emacs试验完了之后再把文件都移动回来,感觉真是好笨拙。

自己写个小脚本

emacs --no-init-file --load CONFIG
1 个赞

看到这里我想请教一个问题:

为什么有些package的作者会建议加上 1 的写法(尤其是一些built-in或很老的package)?

例子:

;;; savehist.el --- Save minibuffer history

;; Copyright (C) 1997, 2005-2018 Free Software Foundation, Inc.

;; Author: Hrvoje Niksic <[email protected]>
;; Maintainer: [email protected]
;; Keywords: minibuffer
;; Version: 24

;; This file is part of GNU Emacs.

...

;; To use savehist, turn on savehist-mode by putting the following in
;; `~/.emacs':
;;
;;     (savehist-mode 1)
;;
;; or with customize: `M-x customize-option RET savehist-mode RET'.
;;
;; You can also explicitly save history with `M-x savehist-save' and
;; load it by loading the `savehist-file' with `M-x load-file'.

;; If you are using a version of Emacs that does not ship with this
;; package, be sure to have `savehist.el' in a directory that is in
;; your load-path, and to byte-compile it.

没啥特殊原因吧……

这些都是过时的文档,可能原来只能那么写,或者是需要支持 Emacs 24.1 之前的版本。

如果文档建议了这种写法

(foo-mode 1)

就不应该再建议用

(add-hook 'prog-mode-hook 'foo-mode)

而只应该建议用

(add-hook 'prog-mode-hook (lambda () (foo-mode 1)))

我的偏好是

  • 越简洁越好
  • 保持一致
2 个赞

按照这个来了一遍,提纲掣领啊

不错不错,麻雀虽小,五脏俱全。

谢谢……

我的偏好是和package作者的指南保持一致,如果作者并未写出指南,那就和最新的写法保持一致

另外,由于我的阅历较浅,除了company-mode和flycheck外,我没见过别的package有关于(add-hook 'after-init-hook 'foo-mode)的建议,大部分还是只有直接加载的建议

经验告诉我只有(foo-mode -1)能可靠地关闭mode,然后启用mode的话因为看到-1有时会跟着写成(foo-mode 1)(foo-mode)显然也可以。其他写法就不可靠了。

Ditto for Customize, which also uses (scroll-bar-mode nil), not -1

Update

As xuchunyang mentioned, the author has changed (scroll-bar-mode nil) into (scroll-bar-mode -1)

简单来讲代码有两种形式,希望给人看的,和不需要给人看的。同种代码,给程序读的格式不能套用在给人读的合适上,举例比如 json。