UP | HOME

目录

启动 spacemacs 时,显示 agenda buffer

~/.spacemacs 配置文件中的 dotspacemacs/user-config 位置加入以下配置内容即可.

(org-agenda-list)
(switch-to-buffer "*Org Agenda*")
(spacemacs/toggle-maximize-buffer)

reddit

添加自定义的 layer

这里以一个具体的场景来说明一下。例如,我现在想安装 wttrin 这个emacs插件。(默认情况下,你通过 M-x package-install RET wttrin RET 安装后,如果重启了emacs,就没有效果了。) 下面是具体的步骤(这里,我创建的layer名为 life-layer

  1. M-x configuration-layer/create-layer <RET> life-layer <RET>
  2. 默认情况下,就保存在 ~/.emacs.d/private/ 就可以了
  3. 然后它会打开配置文件(日后想编辑也可是,路径在 ~/.emacs.d/private/life-layer/packages.el )内容如下:

    ;;; packages.el --- life-layer layer packages file for Spacemacs.
    ;;
    ;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
    ;;
    ;; Author: yangzhiyong <emacsist@yangzhiyongs-MacBook-Pro.local>
    ;; URL: https://github.com/syl20bnr/spacemacs
    ;;
    ;; This file is not part of GNU Emacs.
    ;;
    ;;; License: GPLv3
    
    ;;; Commentary:
    
    ;; See the Spacemacs documentation and FAQs for instructions on how to implement
    ;; a new layer:
    ;;
    ;;   SPC h SPC layers RET
    ;;
    ;; Briefly, each package to be installed or configured by this layer should be
    ;; added to `life-layer-packages'. Then, for each package PACKAGE:
    ;;
    ;; 注意这里的说明,如果你的 layer 是不依赖于 spacemacs 的其他 layer,就为每一个包(在下面 life-layer-packages )定义一个名为 'life-layer/init-包名'的函数来初始化它
    ;; 注意, init-包名 是必须一致的,不然会导致加载该包失败
    ;; - If PACKAGE is not referenced by any other Spacemacs layer, define a
    ;;   function `life-layer/init-PACKAGE' to load and initialize the package.
    
    
    ;; 如果你的某些包是要依赖于 spacemacs 的其他 layer 的,那定义的函数名为 'life-layer/pre-init-包名' 或者 'life-layer/post-init-包名'
    ;; - Otherwise, PACKAGE is already referenced by another Spacemacs layer, so
    ;;   define the functions `life-layer/pre-init-PACKAGE' and/or
    ;;   `life-layer/post-init-PACKAGE' to customize the package as it is loaded.
    
    ;;; Code:
    
    (defun life-layer/init-wttrin()
      (use-package wttrin)
      )
    
    ;;; 这里填写该 layer 依赖的包名
    (defconst life-layer-packages
      '(wttrin)
      "The list of Lisp packages required by the life-layer layer.
    
    Each entry is either:
    
    1. A symbol, which is interpreted as a package to be installed, or
    
    2. A list of the form (PACKAGE KEYS...), where PACKAGE is the
        name of the package to be installed or loaded, and KEYS are
        any number of keyword-value-pairs.
    
        The following keys are accepted:
    
        - :excluded (t or nil): Prevent the package from being loaded
          if value is non-nil
    
        - :location: Specify a custom installation location.
          The following values are legal:
    
          - The symbol `elpa' (default) means PACKAGE will be
            installed using the Emacs package manager.
    
          - The symbol `local' directs Spacemacs to load the file at
            `./local/PACKAGE/PACKAGE.el'
    
          - A list beginning with the symbol `recipe' is a melpa
            recipe.  See: https://github.com/milkypostman/melpa#recipe-format")
    
    
    ;;; packages.el ends here
    
  4. 定义完后,在 ~/.spacemacs (如果的话,可以调用 M-x dotspacemacs/install 来安装一个模板的配置文件)中的 dotspacemacs-configuration-layers() 里加上你的 layer 名。比如:

    dotspacemacs-configuration-layers
    '(
      ;; ----------------------------------------------------------------
      ;; Example of useful layers you may want to use right away.
      ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
      ;; <M-m f e R> (Emacs style) to install them.
      ;; ----------------------------------------------------------------
      spacemacs-helm
      auto-completion
      better-defaults
      emacs-lisp
      git
      markdown
      org
      life-layer
      ;; (shell :variables
      ;;        shell-default-height 30
      ;;        shell-default-position 'bottom)
      ;; spell-checking
      ;; syntax-checking
      version-control
      (colors :variables
              colors-enable-nyan-cat-progress-bar t)
    
      )
    
  5. 重启后即可(或调用 spacemacs/restart-emacs

多光标编辑

这里,以一个具体的例子来进行多光标编辑。假设有一段文本:

hello world
hello1 world
hello2 world

现在想在每个 hello 字符串进行多光标编辑如下:

  1. 将光标移动到第一行的 hello 开头。然后调用( M-x set-mark-command RET ),选取 hello
  2. 这时,再调用 ( M-x iedit-mode RET )
  3. 这时,就是多光标编辑环境了,随便输入什么,它都会在所有匹配到 hello 字符串所在的位置进行同时编辑了。

Emacs中使用 restclient 报 url-http-create-request: Multibyte text in HTTP request

发现emacs里有个非常好用的 HTTP 客户端: restclient 但是在emacs 25.1中发现使用中文请求参数时,报 'multibyte' 的问题。 然后Google了一下,有篇文章帮忙解决了这个问题:cnblogs 下面是具体的步骤(这里以 Mac 下的 emacs 25.1为例)

  1. 定位到emacs的库文件 url-http.el.gz (因为我使用的是 brew 来安装的), 它的文件在:

    [12:47:03] emacsist:lisp $ ls -alh /usr/local/Cellar/emacs/25.1/share/emacs/25.1/lisp/url/url-http.el*
    -rw-r--r-- 1 emacsist admin 17K  3  9 12:32 /usr/local/Cellar/emacs/25.1/share/emacs/25.1/lisp/url/url-http.el.gz
    -rw-r--r-- 1 emacsist admin 37K  3  9 12:34 /usr/local/Cellar/emacs/25.1/share/emacs/25.1/lisp/url/url-http.elc
    [12:47:05] emacsist:lisp $
    
  2. emacs 编辑文件 url-http.el.gzurl-http.elc 是编译之后的文件),将下面的内容:

    ;; Bug#23750
    (unless (= (string-bytes request)
         (length request))
         (error "Multibyte text in HTTP request: %s" request))
    

    修改为如下:

    ;; Bug#23750
    (setq request (url-http--encode-string request))
    (unless (= (string-bytes request)
         (length request))
         (error "Multibyte text in HTTP request: %s" request))
    

    然后保存(注意不要退出)

  3. 编译文件(当前 emacs 已经打开了该文件): 直接输入下在的命令即可: M-x byte-compile-file RET 这样子 emacs 就会将当前文件编译好了。 重启 emacs 即可生效。下面是 restclient 修改后的输出例子:

    中文
    // GET http://localhost:8380/av?text=中文
    // HTTP/1.1 200 
    // Content-Type: text/plain;charset=UTF-8
    // Content-Length: 6
    // Date: Thu, 09 Mar 2017 04:39:51 GMT
    // Request duration: 0.282388s
    

搜索完成后,取消高亮

M-x evil-search-highlight-persist-remove-all RET

新建 buffer 时,设置默认的 major mode

作者: emacsist

Created: 2017-04-05 三 16:59