选中之前选中的区域(Region):C-x C-x
参考文献
Sort lines in a region | Pragmatic Emacs[……]
「Emacs」- Region
「Emacs」- 安装插件,扩展功能
如何自定义配置? EmacsWiki: Init File
章节列表
「GNU Emacs」- 使用标签栏(Tab Bars and Tab Line) 「GNU Emacs」- Emacs X Window Manager 「Emacs」- 显示空白字符 「GNU Emcas」- 文件管理器(File Manager) 「Emacs Speedbar」- 文件模式 「GNU Emacs」- 常用界面设置[……]
「GNU Emacs」- 包管理系统(ELPA, Emacs Lisp Package Archive)
ELPA & package.el
ELPA(Emacs Lisp Package Archive)是 Emacs 的扩展仓库,从 GNU Emacs 24 开始引入。还有很多其他非官方仓库,比如 GnuELPA、Marmalade,以及我们用的最多的 MELPA 仓库。
package.el 是 Emacs 的扩展管理器(实际上是“库”(lib)),包含很多用于管理扩展的函数及命令,可以从 ELPA 中下载扩展、安装扩展,同时也支持搜索、管理等等功能,目的是简化 Emacs 扩展的安装。
配置及使用
第一步、配置扩展仓库
修改 .emacs 或者 ~/.emacs.d/init.el 文件,添加如下配置:
(setq package-archives ‘((“gnu” . “https://elpa.gnu.org/packages/”) ;; GNU ELPA repository (Offical)
(“melpa” . “https://melpa.org/packages/”) ;; MELPA repository
(“melpa-stable” . “https://stable.melpa.org/packages/”) ;; MELPA Stable repository
(“org” . “http://orgmode.org/elpa/”))) ;; Org-mode’s repository
或者,使用 M-x customize-variable [RET] package-archives [RET] 进行配置: 1)Archive name: 填写仓库名,比如 gnu、melpa、melpa-stable 等等; 2)URL or directory name: 填写仓库地址,比如 https://melpa.org/packages/ 地址;
在完成仓库配置后,执行 M-x package-refresh-contents 指令,来创建扩展索引缓存(实际上是下载 archive-contents 文件,并进行处理,然后保存到 /.emacs.d/elpa/archives/<archive-name>/ 目录,该文件保存在某个仓库内全部的全部扩展、下载地址等等信息)。
第二步、安装插件(键盘操作)
1)Type M-x list-packages to open the package list. 2)Press ‘i’ to mark for installation, ‘u’ t[……]
「GNU Emacs」- Emacs Application Framework (EAF)
manateelazycat/emacs-application-framework: Emacs application framework[……]
「GNU Emacs」- Emacs X Window Manager
ch11ng/exwm: Emacs X Window Manager EXWM – ArchWiki[……]
「GNU Emacs」- 常用界面设置
问题描述
该笔记将记录:在 GNU Emacs 中,那些 常用的、整体的、较小的 界面设置,或者某些交互方式。比如,修改全局字体、关闭 Tooltip 功能、设置 yes-or-no 为 y-or-n 模式等等。
该笔记的子章节将记录:在 GNU Emacs 中,与界面相关的设置,包括 Frame、Window、Mode Line 等等方面的设置。
字体设置(Font configuration)
修改全局字体(默认字体): 1)M-x customize-face [RET] default 2)修改 Font Family: 字段
设置备用字体(如果 A 字体没有字符,则到 B 字体中查找): 1)M-x customize-variable [RET] face-font-family-alternatives 2)已存在默认设置,如说明中的介绍,如果 FAMILY 没有找到,将使用 ALTERNATIVE1 ALTERNATIVE2 依此类推。
修改代码注释颜色: 1)M-x customize-face [RET] font-lock-comment-face [RET], 2)orange red (#ff4500) Bold(代码是写给机器看的,注释才是写给人看的,我们需要稍微突出显示注释)
弹窗提示
在某些操作中,会弹窗提示用户进行选择,而我们希望可以直接在 Echo Area 中显示,并通过键盘操作完成,而不是鼠标点击操作,以提高效率(其实也没有提升多少)。
为解决该问题,在初始化脚本(比如 ~/.emacs 文件)中,加入如下配置即可:
(setq use-dialog-box nil) ; 禁止显示那些“需要鼠标点击的”弹窗,改为使用 y/n 按键操作
或者,使用 Customize 设置:M-x customize-variable [RET] use-dialog-box
关闭 Tooltip 功能
该功能(Tooltip)很常见,比如,在应用中,将鼠标浮动到图标按钮上,将显示小的窗口,以提示按钮名称、功能、描述等等。在 GNU Emacs 中,开启 Tooltip 功能,当鼠标浮动到按钮上时,可以显示按钮功能、左右鼠标键对应的功能、显示到 Each Area 区域中等等。
但是,我们不需要该功能(有各种原因),在初始化脚本(比如 ~/.emacs 文件)中,加入如下配置即可:
(setq x-gtk-use-system-tooltips nil) ; 关闭 tooltip 功能
(tooltip-mode -1) ; 阅读手册(C-h f tooltip)获取设置方法
或者,使用 Custom[……]
「GNU Emacs」- 常用 Frame 设置
解决方案
修改 Frame 名称(设置窗口标题)
问题描述:由于 Sr Speedbar 不能在多个 Frame 中同时打开,因此我们只能运行多个 Emacs 实例。但是,带来的问题是,多个实例的窗口名相同,在使用 Alt+Tab 切换时,难以区分。因此,我们希望可以重命名窗口标题,以便于我们进行区分。
解决方法有以下几种:
1)安装 frame-fns.el 与 frame-cmds.el 扩展,后者依赖于前者。注意,该插件无法通过 package.el 安装,只能直接下载安装:
;;;; 我们保存无法使用 package.el 安装的插件的目录
(add-to-list ‘load-path “~/.emacs.d/mextra/”)
;;;; 修改 .emacs 配置,加载并启用
(require ‘frame-cmds)
;;;; 使用 M-x rename-frame [RET] <current name> [RET] <new name> [RET]
2)使用 frame-title-format 变量:(TODO) frames – Set a title to an Emacs instance running in a terminal – Emacs Stack Exchange 29.6 Frame Titles EmacsWiki: Frame Title Dynamic title for Treemacs workspace – Andrey Listopadov
参考文献
EmacsWiki: Frame Title[……]
「GNU Emacs」- 常用 Mode Line 设置
Mode Line / Major Mode
在 Mode Line 中,修改 Major Mode 样式:M-x customize-face RET mode-line-buffer-id RET
我们取消字体加粗(Weight/normal),因为字体加粗会使 Mode Line 高出 1 像素。
参考文献
faces – How to make buffer name in mode-line be bold when its window is selected? – Emacs Stack Exchange[……]
「GNU Emacs」- 常用 Window 配置
问题描述
该笔记将记录:在 GNU Emacs 中,与 Window 有关的设置。
解决方案
最大化当前 Window,并能切换(toggle)
在 Emacs 中,将 Frame 分割为多个 Window 之后,每个 Window 就会变小(毕竟 Frame 大小是有限的。
我们希望可以像 tmux 那样,将当前 pane 最大化(隐藏其他 panne),然后再切换回来。
在 GNU Emacs 中,有以下几种方式实现: 1)delete-other-windows + winner-mode,解释:delete-other-windows 负责关闭除当前的其他 Window,而 winner-mode 用于恢复之前的 Window 布局。 2)使用 zoom-window 插件(我们采用的方式)
如下笔记将记录,如何使用 zoom-window 来切换 Window 最大化: 1)M-x package-install [RET] zoom-window [RET] 2)在 ~/.emacs 中,添加绑定 zoom-window-zoom 的快捷键:
(global-set-key (kbd “s-z”) ‘zoom-window-zoom) ;; Super + z / Window + z
参考文献
Learning emacs part 4: buffers, windows, and frames – Blasphemous Bits EmacsWiki/WinnerMode 20.7 Convenience Features for Window Handling In Emacs, can we maximize current active window, and then restore it back in multiple window environment? – Stack Overflow emacsorphanage/zoom-window: Zoom and Unzoom window[……]
「GNU Emacs」- Window Fringes
参考文献
14.14 Window Fringes[……]
「Emacs」- 同时编辑多行文本
问题描述
同时编辑多行,即在多行文本中显示光标,然后进行编辑,如下截图:
解决办法
安装 magnars/multiple-cursors.el: Multiple cursors for emacs. 插件
附加说明
还有种做法是使用 Rectangles – GNU Emacs Manual 功能
参考文献
in Emacs, edit multiple lines at once – Stack Overflow[……]
「GNU Emacs」- 使用 TRAMP 编辑远程文件
参考文献
dired – Edit file with super-user rights – Emacs Stack Exchange EmacsWiki: Tramp Mode[……]
「Emacs」- 创建加密文件
EasyPG是Emacs中的GPG接口。分为两个方面:允许使用Emacs(EasyPG Assistant)的GnuPG的快捷工具,以及GnuPG(EasyPG Library)的全功能接口库。
在目前的Emacs版本(25.0)中,已经内置了EasyPG。
并且eap-file-enable属性已经默认启动,该属性启用后Emacs会把以.gpg结尾的文件默认视为需要解密的文件,所以使用C-f C-x创建以.gpg结尾的文件就可以了。当执行保存的时候,Emacs会提示你选择密钥类型,并设置密码。
参考文献
EmacsWiki/Easy PG[……]
「GNU Emcas」- 文件管理器(File Manager)
文件管理器(文件浏览器)
从命令行操作时,有方便的地方,也有不方便的地方,比如,文件浏览、文件查找。
我们需要使用文件管理器,以进行文件的快速查找、快速浏览等等。
该笔记将记录:在 Emacs 中,如何使用的文件管理器(文件浏览器) –
解决方案
Speedbar & Sr Speedbar
Speedbar 是自带文件浏览器。在启动后,将打开新窗口,可以进行文件打开、删除等等操作。
Speedbar 的使用方法,参考文档:Emacs Manual/21.9 Speedbar Frames Introduction – 基本介绍 Basic Navigation – 在各模式下都支持的操作、快捷键绑定等等。 File Mode – 文件模式 Buffer Mode – 缓冲模式 Minor Modes – 次要模式 Customizing – 调整Speedbar行为 Extending – 根据自己需要,调整Speedbar行为
Sr Speedbar 可以使 Speedbar 嵌入到 Emacs 窗口里,而不是打开新窗口,因此功能与 Speedbar 相同。
Sr Speedbar 的使用方法,参考文档:Emacs Wiki/Sr Speedbar
Dired Mode
EmacsWiki/Dired Mode
看完「.Emacs #4 – Exploring the Filesystem with Dired」这个视频之后,我就决定使用dird了。
最重要的是可以使用 Tramp Mode 来访问和浏览远程的文件。
Treemacs
Alexander-Miller/treemacs
附加说明
还有其他的文件管理器很多,参考 A good project tree browser for Emacs? 问题。
如果想在指定的在 Window 中打开文件,可以使用 Purpose 扩展。
我们的选择
# 12/08/2017 我们使用 Dired Mode 和 Sr Speedbar 这两个,它们都能解决我的问题,包括远程目录浏览。
# 01/31/2021 Treemacs 是我们目前正在使用的文件管理器。
参考文献
What is Beginner friendly File Manager for Emacs ? .Emacs #4 – Exploring the Filesystem with Dired A good project tree browser for Emacs? How can I open the files only in a specific window in[……]
「Emacs」- Speed Bar
Speedbar是Emacs的一个程序,可以用来汇总显示当前Buffer相关的信息。相当于一个文件浏览器,但还包含了其他功能。
Speedbar显示一个显示树形的视图。此视图默认为文件和目录的列表。其中的「文件」可以“展开”显示文件中包含的「标签」(tag,类似于IDE中的源码包含的函数预览功能)。「目录」可以“展开”显示其中包含的文件。每个「文件」或「标签(tag)」可以进行“点击跳转”。
Speedbar通过“维护用户上下文”来扩展“资源管理器”窗口。例如,在使用文件视图时,当前缓冲区的文件被突出显示。Speedbar也通过提供多种显示模式来模拟浏览窗口。这些模式有两种:「主显示模式」在缓冲区中保持一致,只有在显示适用类型的缓冲区时,才会显示次显示模式。这使得其他Emacs插件的作者可以根据插件模式的需要来设置Speedbar显示的内容。
在次,「活动」被定义为“点击”或“展开”项目。「点击」表示使用mouse-2按钮(鼠标)。「展开」是指单击「展开按钮」以显示「展开按钮所在位置」的「展开摘要」。
功能简介
使用命令M-x speedbar RET或从“Options -> Show/Hide”的子菜单中打开Speedbar,这个命令将打开一个新Frame,这个新Frame就是Speedbar,Speedbar中会显示本地文件列表。 在X Window系统或MS-Windows上,Speedbar宽度为20个字符,并且高度等于之前Frame的高度,位于之前Frame的左侧或右侧。
要有效地使用Speedbar,重要的是了解Speedbar与启动Speedbar的绑定Frame(执行Speedbar命令是所在的Frame)之间的关系。该Frame是Speedbar用作参考点的「附加Frame」。Speedbar一旦启动,就会观察该「附加Frame」的内容,并尝试使Speedbar的内容与加载到「附加Frame」中的Buffer的内容相关。另外,所有在Speedbar中产生的要求显示另一个Buffer的请求(比如:打开文件),都会显示在「附加Frame」中。
在终端模式下时,新Frame显示与终端相同的尺寸。由于在附加Frame中工作时Speedbar不可见,因此Speedbar将通过使用slowbar mode来节省时间,在Speedbar被要求显示自身之前(即,Speedbar所在的Frame变为选中的Frame)不进行“内容显示跟踪”。
使用键盘在Frame之间切换时,使用的函数是speedbar-get-focus,这个函数将在不同的Frame之间切换,在终端模式下绑定到一个键是很有用的。
参考文献
EMACS/Speedbar[……]
「Emacs Speedbar」- 基础功能导航
Speedbar可以显示不同类型的数据,并具有多种显示模式和行为模式。
这些模式都有一个共同的行为、菜单系统、外观。如果学习了一种模式,那么其他模式很容易使用。
基础快捷键(Basic Key Bindings)
这些快捷键是在所有的模式中通用的:
Q Quit speedbar, and kill the frame.
q Quit speedbar, and hide the frame. This makes it faster to restore the speedbar frame, than if you press Q.
g Refresh whatever contents are in speedbar.
t Toggle speedbar to and from slowbar mode. In slowbar mode, frame tracking is not done.
n p Move, respectively, to the next or previous item. A summary of that item will be displayed in the attached frame’s minibuffer.
M-n M-p 同级间移动,跳过同级的子菜单。 Move to the next or previous item in a restricted fashion. If a list is open, the cursor will skip over it. If the cursor is in an open list, it will not leave it.
C-M-n C-M-p Move forwards and backwards across extended groups. This lets you quickly skip over all files、directories、or other common sub-items at the same current depth.
C-x b Switch buffers in the attached frame.
模式切换
Speedbar可以处理多种模式。有两种模式是默认的:「File模式」和「Buffer模式」。以下的快捷键可以在两种模式间快速切换:
b Switch into Quick Buffers mode (see Buffer Mode). After one use, the previous display mode is restored.
f Switch into File mode.[……]
「Emacs Speedbar」- 文件模式
内容简介
本文将整理在Speedbar中的文件模式下的相关内容。
快捷键绑定
3.3 File Key Bindings
Shift + U 是Speedbar显示”上一目录“(注意与”上级目录“区分)内容。
参考文献
Command to navigate up one directory in speedbar?[……]
「GUN Emacs」- 禁止 Sr Speedbar 水平滚动(未解决)
问题描述
在编辑器的文件浏览器(EXPLORER)中,是不会发生水平滚动的。如果文件名过长,超出的部分将显示为省略号(…)。在 GUM Emacs / Speedbar 中,也是如此。
但是在 Sr Speedbar 中,却能水平滚动,这台不正常了,影响正常使用。(这可能与 Sr Speedbar 实现相关)
解决方法
方法一、使滚动条保持在最左侧
方法二、检测并调整光标位置
(defun k4nz/show-current-column ()
(message “current position: %s” (current-column)))
(add-to-list ‘post-command-hook ‘k4nz/show-current-column)
参考文献
an Emacs cursor movement hook, like the JavaScript mousemove event – Stack Overflow 39.4.1 Displaying Messages in the Echo Area 32.16 Counting Columns[……]
「Emacs」- Sr Speedbar
使用方法
sr-speedbar-open 打开Sr Speedbar窗口。
sr-speedbar-close 关闭Sr Speedbar窗口。
sr-speedbar-toggle 切换Sr Speedbar窗口。
sr-speedbar-select-window 选择Sr Speedbar窗口,即切换到到Sr Speedbar窗口。
sr-speedbar-refresh-turn-on 开启Sr Speedbar内容刷新。
sr-speedbar-refresh-turn-off 关闭Sr Speedbar内容刷新。
sr-speedbar-refresh-toggle 切换Sr Speedbar内容刷新。
参考文献
Sr Speedbar在EmacsWiki中的地址 如何固定Sr Speedbar中的目录[……]
「GNU Emacs」- Treemacs(文件管理器)
问题描述
之前(01/31/2021),我们一直使用 Speedbar 与 Sr Speedbar 进行文件管理,但是问题太多。在配合 Tab Bar 使用时,也存在问题。因此,我们开始寻找其他可以替代 Speedbar 与 Sr Speedbar 的工具。
后来,找到并使用 Treemacs 来进行文件管理。如下为 Treemace 界面截图:
该笔记将记录:Treemacs 的使用方法及相关设置。
解决方案
项目仓库:Alexander-Miller/treemacs 安装方法:M-x package-install RET treemacs RET
常用设置记录
调整宽度
如果只是临时调整,可以取消锁定: 1)执行 M-x treemacs-toggle-fixed-width 命令,取消宽度锁定; 2)使用鼠标,手动调整宽度; 3)执行 M-x treemacs-toggle-fixed-width 命令,进行宽度锁定;
如果希望设置为自己满意的宽度,需要设置 treemacs-width 属性: 1)M-x customize-variable RET treemacs-width
调整每级目录的缩进长度
父目录与子目录,距离左侧的距离是不同的,因此我们才能区分出,哪个是父目录,哪个是子目录。
但是,默认的距离可能太长(或者太短),因此我们需要调整这个距离。有如下两种方法: 1)treemacs-indentation-string 指定用于缩进的字符串;treemacs-indentation 指定字符串重复次数
M-x customize-variable RET treemacs-indentation-string
M-x customize-variable RET treemacs-indentation
2)或者,使用 treemacs-indentation 指定缩进像素数
M-x customize-variable RET treemacs-indentation => Value Menu / Pixels
补充,我们使用缩进 10px 或者 1 x SPACE 设置。
参考文献
Alexander-Miller/treemacs[……]
「Emacs」- Fill Column Indicator
问题描述
在现代编辑器中,比如 Eclipse,一般都会显示 Print Margin 竖线,通常在第 80 列处,以指示代码列宽,告诉我们单行代码不要写的太长。
我们需要使用该功能,以控制单行代码不要写的太长,提高代码可读性。(当然也有人喜欢关闭它,我们这里要介绍开启它)
该笔记将记录:在 GNU Emacs 中,如何启用打印边界(Print Marin)。
解决方案
方案一、使用 Fill Column Indicator 扩展
以前(09/16/2021)我们使用 EmacsWiki: Fill Column Indicator 扩展: 1)安装 fill-column-indicator 插件:M-x package-install RET fill-column-indicator 2)执行 fci-mode 命令:M-x fci-mode
如果希望默认启用,则需要在初始化文件中(~/.emacs),添加如下配置:
(define-globalized-minor-mode global-fci-mode fci-mode (lambda () (fci-mode 1)))
(global-fci-mode 1)
// 如果,仅希望在特定模式中启用,则添加如下配置
(setq enable-fci-mode-in ‘(groovy-mode nasm-mode shell-mode))
(define-globalized-minor-mode global-fci-mode fci-mode (lambda () (if (member major-mode enable-fci-mode-in) (fci-mode 1))))
(global-fci-mode 1)
# 02/03/2021 由于 Fill Column Indicator 存在问题,比如在 Customize Group 中会破坏页面布局、有时显示也会存在问题,所以我们不再使用它,而是使用 Emacs 27 内置的 Displaying Boundaries 功能。
方案二、使用 Displaying Boundaries 功能(推荐)
推荐原因是,这是 Emacs 27 内置的功能,与 Fill Column Indicator 类似,并且不存在使用 Fill Column Indicator 所遇到的问题。详细说明,参考 14.15 Displaying Boundaries 文档。
启用功能:M-x global-display-fill-column-indicator-mode
默认启用:M-x customize-variable RET global-disp[……]
「Emacs」- 显示空白字符
显示空白字符
whitespace-mode
将制表符替换为空格
.emacs: (setq-default indent-tabs-mode nil)
remove tabs in an existing file: C-x h M-x untabify
does the opposite: M-x tabify
相关连接
EmacsWiki/Tabs Are Evil
参考文献
EmacsWiki/Show White Space EmcasWiki/No Tabs[……]
「GNU Emacs」- 高亮设置(Highlight)
问题描述
通过高亮(Highlight),可以区分内容、突出显示,帮助我们阅读文章内容。比如:在代码中,高亮成对出现的括号,可以让我们快速发现问题;
该笔记将记录:在 GNU Emacs 中,如何进行各种高亮设置,比如 高亮当前行、高亮选中文本、高亮匹配特定文本的行 等等。
解决方案
高亮选中文本:M-x customize-variable RET,搜索 Region 并修改 Region 字段
高亮当前行
M-x customize-group [RET] hl-line [RET],然后修改如下参数: 1)Global Hl Line Mode:全局启用高亮当前行; 2)Hl Line face / Backgroud:高亮当前行的背景颜色;
但是,如果当前行没有 LF(换行字符),是无法高亮整个行的(这也是我们使用 高亮当前行号 方案的原因)。
高亮当前行号
做为 高亮当前行 的替代方案 —— 高亮当前行号,有以下几种方案: 1)linum-mode + hlinum-mode,插件 hlinum-mode 本就是 linum-mode 的扩展; 2)display-line-numbers-mode,推荐方法,该插件是用于显示行号,但是支持高亮当前行号;
在 display-line-numbers-mode 中,高亮当前行号的方法如下: 1)M-x customize-group [RET] display-line-numbers [RET] 2)修改 Line Number Current Line face: 属性
高亮匹配的括号
EmacsWiki: Show Paren Mode 26.4.3 Matching Parentheses
M-x customize-group [RET] paren-showing [RET],然后修改如下参数: 1)Show Paren Mode:启动高亮括号模式; 2)Show Paren Style:选择 parenthesis 选项,高亮括号;选择 expression 选项,高亮括号及内容;
高亮匹配特定内容的行
regex – Highlight whole line (from left border to right border) in Emacs’ regexp mechanism – Stack Overflow highlighting – How to highlight all occurrences of a word in an Emacs buffer? – Stack Overflow
使用 highlight-regexp 实现。
但是,我们希望可以高亮整[……]
「GNU Emacs」- 行号操作(显示、统计、定位)
问题描述
在阅读技术书籍时,作者使用行号来引用示例代码。我们需要知道示例代码的行号,以快速定位到示例代码的对应位置。
在日常代码编辑中,我也们需要查看行号: 1)以快速定位到特定行(某些情况会快于使用 goto-line 命令); 2)在描述问题时,通过代码所在的行号进行定位代码;
该笔记将记录:在 GNU Emacs 中,显示行号的方法。注意,我们所说的“显示行号”除了在左侧显示行号,还包括显示当前行号、统计总行数等等。
解决方案
显示当前行号: 1)M-x what-line [RET],将在回显区(Echo Area)显示当前光标(Point)所在行号。 2)M-x line-number-mode [RET],将在状态行(Mode Line)中显示光标(Point)所在行号。
统计页面行数 1)使用 C-x l 或 M-x count-lines-page 将在回显区(Echo Area)显示当前页面总行数,以及光标(Point)所在行、光标后面的行数。
快速定位到特定行号 1)M-x goto-line [RET] <LINE-NUMBER> [RET] 2)或者,M-g M-g <LINE-NUMBER> [RET]
显示左侧行号
linum-mode
对于旧版(GNU Emacs 26-),使用 linum-mode(属于 linum.el)扩展
通过如下配置,以实现仅在特定模式中显示行号:
(require ‘linum)
(set ‘display-line-numbers-certain-modes ‘(masm-mode nasm-mode))
(defun linum-on ()
(if (or (minibufferp) (member major-mode display-line-numbers-certain-modes))
(linum-mode 1)))
(global-linum-mode 1)
根据 Emacs 说明,浏览较大文件,将会出现我问题(View large file more than 300000 lines very slow. · Issue #178 · redguardtoo/emacs.d)。
# 03/04/2021 我们不再使用 linum-mode 的原因是 linum-mode 可定配置的功能较少,并且不是官方提供的插件。
display-line-numbers-mode(正在使用)
display-line-numbers-mode is available since Emacs 26,我们目前(09/30/2020)[……]
「GNU Emacs」- 快速切换窗口(Window)
问题描述
在 GNU Emacs 中,切换窗口(Window)是件麻烦的事情(20.3 Using Other Windows),因为我们希望按下快捷键,直接切换到特定窗口(Window),而不是快捷键组合。
该笔记将记录:在 GNU Emacs 中,在窗口(Window)间快速切换的方法。
解决方案
我们有两个选择:EmacsWiki: Numbered Windows 与 EmacsWiki: Window Numbering Mode 插件
Numbered Windows
window-number-mode is an interactive compiled Lisp function in ‘window-number.el’. nikolas/window-number: Select windows by M-1, M-2, etc in Emacs
安装该插件以后,需要修改配置进行启用:
(require ‘window-number)
(window-number-mode 1)
显示位置,如下截图(红底 [1] 位置)。似乎没有直接可以直接调整的参数,除非修改 Mode Line 配置(因此我们不使用它):
Window Numbering Mode(推荐)
window-numbering-mode is an interactive autoloaded compiled Lisp function in ‘window-numbering.el’. nschum/window-numbering.el: Emacs: Numbered window shortcuts
我们使用 window-numbering.el 插件,通过 M-x window-numbering-mode 开启。
它将在模式行(Mode Line)的最开始显示数字(这是我们选择该扩展的原因),来指示当前窗口的序号,然后使用 M-<number> 进行窗口切换。
选型没有什么特别的原因,可能是因为我们一直都在使用 Window Numbering Mode 插件,还有就是 Numbered Windows 显示数字样式及位置不符合我们的审美 :-)
我们的配置参数:
(require ‘window-numbering)
(defun window-numbering-get-number-string (&optional window)
(let ((s (int-to-string (window-numbering-get-number window))))
(propertize ([……]
「GNU Emacs」- 滚动条设置
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; 滚动条设置
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 水平滚动条
(scroll-bar-mode -1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 垂直滚动条
(horizontal-scroll-bar-mode -1)
(setq hscroll-margin 1) ; 「当前行的最后列」距离「右面」的边距,无需太远
(setq hscroll-step 1) ; 当光标移动到当前显示区域边缘时,自动左移一个字符,无需太多(如果需要预览,可以增加该参数)
相关链接
EmacsWiki: Scrolling EmacsWiki: Smooth Scrolling 28.21 Textual Scrolling
参考文献
EmacsWiki: Scroll Bar Changing Horizontal Scrolling in Emacs – Stack Overflow[……]
「GNU Emacs」- 使用标签栏(Tab Bars and Tab Line)
问题描述
在 GNU Emacs 中,虽然 Frame 可以切割为多个 Window 以同时显示多个文件。但是受显示器的尺寸的限制,Window 依旧比较小。
我们可以使用标签栏,而仅在必要的时候使用 Window 分割功能。标签栏是个常用功能,是在历史中沉淀下来的界面交互,我们怎么可能错过呢。
该笔记将记录:在 Emacs 中,如何配置并使用标签栏。
解决方案
GNU Emacs 26.1
使用 tabbar.el 插件,参考 EmacsWiki: Tab Bar Mode 页面。(我们不打算学习 tabbar.el 插件,而是直接使用 Emacs 27.1 引入的 Tab Bars 及 Tab Line 功能)
GNU Emacs 27.1
Note: Emacs 27.1 will come with two built-in tab modes, tab-bar-mode (per-frame) and tab-line-mode (per-window). See documentation for details. Tab-line-mode is similar to tabbar.el described on this page, with one buffer per tab. Tab-bar-mode is for storing one window configuration per tab.
Tab Bars(学习笔记)
我们这里仅进行关键内容的介绍。详细使用及其他内容,参考 21.17 Tab Bars 文档。
功能介绍
Tab Bars,用于保存当前在 Frame 中 Window 的布局(配置)。使用 M-x tab-bar-mode 启动。
如下截图,当在 TB-00 与 TB-01 间相互切换时,可以切换到对应的窗口布局,这就是 Tab Bars 的主要功能,即保存当前 Window 的布局:
常用快捷键
M-x tab-bar-mode,启用 M-x t 2,创建新的 Tab M-x t 0,关闭当前 Tab M-x t r,重命名当前 Tab
常用设置
Tab Bars 的大多数属性设置,需要通过 M-x customize-group RET tab-bar RET 完成,多半无法通过变成配置完成。
使用数字快速切换 Tab:设置 tab-bar-select-tab-modifiers 属性。
Tab Line(学习笔记)
我们这里仅进行关键内容的介绍。详细使用及其他内容,参考 20.8 Window Tab Line 文档。
功能介绍
Tab Line,便是我们常用的选项[……]
「Emacs」- 配置编程环境
gRPC / Protocol Buffers
使用 protobuf-mode 模块:M-x package-install [RET] protobuf-mode [RET][……]
「GNU Emacs」- 自动补全(配置笔记)
使用 AutoComplete 扩展
# 03/04/2021 我们创建该章节,开始使用 Auto Complete 自动补全,该章节将记录 Auto Complete 的使用笔记。
安装 Auto Completion 模块
auto-complete/auto-complete: Emacs auto-complete package
全局开启自动补全功能
init file – How do I make auto-complete enabled by default – Emacs Stack Exchange
1)M-x customize-variable [RET] global-auto-complete-mode [RET] 2)Global Auto Complete Mode: on
通过 Emacs 快捷键来选择补全内容
在 Auto Complete 中,默认使用上下键来选择,而我们希望使用 C-n C-p 来选择。需要进行如下设置: 1)M-x customize-group [RET] auto-complete [RET] 2)设置 Ac Use Menu Map: on 属性;
Python 自动补全
# 07/10/2019 这是首次接触 Emacs 的自动补全。
自动补全是如何工作的?
自动补全的工作流:Frontend => Backend => Python Module => Static Analysis
在 Frontend 中,我们与提供自动补全的模式 (比如CompanyMode/AutoComplete等等)交互,它们调用一些 后端的Emcas模块 (比如company-jedi/Jedi.el等等),这些后端模块调用一些 Python 模块 (比如jedi/rope等等),这些 Python模块 负责代码静态分析,导入相应的包。
Frontend,有两种, CompanyMode 与 AutoComplete 目前(07/10/2019),我们使用的是 CompanyMode 。因为从 GitHub 上看,上次插件更新时间是六天前(03/24/2019),而另一个是2017年的,难不成是太稳定了???
Backend,只有两个选择:company-jedi 和 Ropemacs 目前(07/10/2019),我们使用 Ropemacs(这是根据插件在 GitHub 上的更新时间来看的。收到的另外一个好处是 Ropemacs 可以同时作为 CompanyMode 和 AutoComplete 模式的后端。
我们的选择
CompanyMode => Ropemacs[……]
「GNU Emacs」- Markdown Mode for Emacs(编写 Markdown 文档)
笔记内容
插件 Markdown Mode for Emacs 用于在 Emacs 中编写 Markdonn 文档并预览,以及进行其他 Markdown 操作。
该笔记将整理:与该插件有关的内容。
插件信息
Version: 20201015.1327 GitHub: https://github.com/jrblevin/markdown-mode
安装插件
安装,参考 Markdown Mode for Emacs(markdown-mode/README.md) 或 Guide to Markdown Mode for Emacs 文档
注意事项
1)在安装该插件后,即可编写 Markdown 文档。 2)但是预览需要安装额外的 Markdown 命令(Linux Command),并设置 markdown-command 变量
常用配置
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Markdown
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; 配合 Imenu 显示 Markdown 导航菜单,以进行快速切换章节
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; https://jblevins.org/log/markdown-imenu
;;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; 动态预览设置
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; https://unix.stackexchange.com/questions/4140/markdown-viewer
(setq markdown-command “pandoc”) ;; 使用 pandoc 进行 markdown 导出,该命令支持更多 markdown 特性
(setq markdown-split-window-direction ‘right) ;; 动态预览窗口在右侧打开
;; 设置预览使用的浏览器
; 在原有默认配置中,使用 eww 浏览器
; (setq markdown-live-pr[……]