Emacs Modes

Emacs Modes

常用mode安装说明和使用

org-mode

lsp

dap

介绍

类似lsp-mode用于开发,dap-mode用于提供协议支持,各种语言的debugf

consunl

ivy

yasnippet

company

最近发现很多时候,我的补全包括org-mode, c-mode, python-mode等都不太好,所以学习下大名鼎鼎的company-mode。

老规矩先阅读下官方文档

参见company_mode官方文档

介绍

company-mode究竟是什么呢?

company是一个emacs的补全插件,通过结合常见的backends实现补全anything。常见的有Elisp, Clang, Semantic, Ispell, CMake, Yasnippet, Dabbrev, Etags, Gtags, Files, Keywords等。

CAPF这个backend负责和每个主mode之间的complete-at-point-functions进行进行传递,类似一个桥梁作用。

配置

可以参考下文末的emacs wiki

我的配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; init-company.el --- company-mode settings        -*- lexical-binding: t; -*-
;;; Commentary:
;;; Copyright (C) 2021  liuliancao

;;; Author: liuliancao <liuliancao@liuliancao>
;;; Keywords: languages
;;; Code:

(use-package company
  :after lsp-mode
  :hook (lsp-mode . company-mode)
  :bind (:map company-active-map
              ("<tab>" . company-complete-selection))
  (:map lsp-mode-map
        ("<tab>" . company-indent-or-complete-common))
  :config
  ;;(diminish 'company-mode)

  (global-set-key (kbd "M-C-/") 'company-complete)
  (define-key company-mode-map (kbd "M-/") 'company-complete)
  (define-key company-mode-map [remap completion-at-point] 'company-complete)
  (define-key company-mode-map [remap indent-for-tab-command] 'company-indent-or-complete-common)
  (define-key company-active-map (kbd "M-/") 'company-other-backend)
  (define-key company-active-map (kbd "C-n") 'company-select-next)
  (define-key company-active-map (kbd "C-p") 'company-select-previous)
  (define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
  (define-key company-active-map (kbd "M-.") 'company-show-location)
  (setq-default company-dabbrev-other-buffers 'all
                company-tooltip-align-annotations t)

  (setq company-tooltip-limit 10) ; bigger popup window
  (setq company-idle-delay 0) ; decrease delay before autocompletion popup shows
  (setq company-echo-delay 0) ; remove annoying blinking
  (setq company-begin-commands '(self-insert-command)) ; start autocompletion only after typing
  (setq company-minimum-prefix-length 2)
  (setq company-backends
        '((company-files
           company-yasnippet
           company-keywords
           company-capf
           company-elisp
           company-abbrev
           company-dabbrev
           )))

  (advice-add 'company-complete-common :before (lambda () (setq my-company-point (point))))
  (advice-add 'company-complete-common :after (lambda () (when (equal my-company-point (point)))))
  (use-package company-quickhelp
    :ensure t)
  )

(provide 'init-company)
;;; init-company.el ends here

使用

M-/ 对应函数为company-complete也就是按Alt加右边shift左边的?那个键

auto-insert-mode

更具体的可以看emacs wiki auto-insert-mode

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
;;; init-autoinsert.el --- autoinsert                -*- lexical-binding: t; -*-
;;; Commentary:
;;; Copyright (C) 2021  liuliancao

;;; Author: liuliancao <liuliancao@gmail.com>
;;; Keywords: languages
;;; Code:
(use-package autoinsert
  :ensure t
  :init (auto-insert-mode t)
  :config
  (define-auto-insert '(python-mode . "Python skeleton")
    '("Auto insert python heading: "
      "#!/usr/bin/env python3" \n
      "# -*- coding: utf-8 -*-" \n
      "# Date: " (substring (current-time-string)) \n
      "# Author: " (progn user-full-name) " <liuliancao@gmail.com>" \n
      "# Copyright (c) @xxx" \n
      "\"\"\"Description: \"\"\"" \n \n
      ))
      )
;;; init-autoinsert.el ends here

引入完以后,再打开新文件的时候就会提示是否auto-insert, 选择是则插入开头

projectile

最近使用=projectile=遇到一些问题,所以这里简要学习一下,projectile是emacs管理项目的一个利器。由于其

本身和很多工具比如rg、lsp等,所以使用起来非常方便。

projectile的官方文档 projectile githubprojectile docsprojectile中文介绍文档

我的简单配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
;;; init-projectile.el --- Use Projectile for navigation within projects -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(use-package projectile
  :diminish projectile-mode
  :bind-keymap
  ("C-c p" . projectile-command-map)
  :config
  (setq-default projectile-mode-line-prefix " Proj")
  (when (executable-find "rg")
    (setq-default projectile-generic-command "rg --files --hidden"))
  (use-package ibuffer-projectile
    :ensure t)
  )
(provide 'init-projectile)
;;; init-projectile.el ends here

简单使用

  • 我对projectile的配置比较简单, 一般我们使用C-c p切换项目,切换完成以后会提示选择对应的文件,
  • 在当前项目中,C-c p f可以方便得检索文件
  • 在当前项目中,查找字符串C-c p s s可以检索字符串(也可以用M-x ag-files)
  • 关闭本项目中的buffer,C-c p k

projectile怎么确认这是一个项目呢,有一些关键的文件标识

file flags

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
rebar.config	Rebar project file
project.clj	Leiningen project file
build.boot	Boot-clj project file
deps.edn	Clojure CLI project file
SConstruct	Scons project file
pom.xml	Maven project file
build.sbt	SBT project file
gradlew	Gradle wrapper script
build.gradle	Gradle project file
.ensime	Ensime configuration file
Gemfile	Bundler file
requirements.txt	Pip file
setup.py	Setuptools file
tox.ini	Tox file
composer.json	Composer project file
Cargo.toml	Cargo project file
mix.exs	Elixir mix project file
stack.yaml	Haskell's stack tool based project
info.rkt	Racket package description file
DESCRIPTION	R package description file
TAGS	etags/ctags are usually in the root of project
GTAGS	GNU Global tags
configure.in	autoconf old style
configure.ac	autoconf new style
cscope.out	cscope
Makefile	Make

当然也可以使用自带的.projectile标识

eaf

eaf项目地址 eaf让emacs支持了更多应用,且对图形化支持更好,通过模块化的思想,让emacs能运行更多应用

参考readme安装一下

1
2
3
4
5
git clone --depth=1 -b master https://github.com/emacs-eaf/emacs-application-framework.git ~/.emacs.d/site-lisp/emacs-application-framework/
cd ~/.emacs.d/site-lisp/emacs-application-framework/
./install-eaf.py
# 我选择安装了所有的组件~
# 挺久的,大概半小时

最终会提示加入如下组件到init.el

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
[EAF] Please ensure the following are added to your init.el:
(require 'eaf-mermaid)
(require 'eaf-file-browser)
(require 'eaf-camera)
(require 'eaf-org-previewer)
(require 'eaf-file-manager)
(require 'eaf-browser)
(require 'eaf-image-viewer)
(require 'eaf-vue-demo)
(require 'eaf-jupyter)
(require 'eaf-mindmap)
(require 'eaf-file-sender)
(require 'eaf-pdf-viewer)
(require 'eaf-markdown-previewer)
(require 'eaf-airshare)
(require 'eaf-demo)
(require 'eaf-music-player)
(require 'eaf-video-player)
(require 'eaf-rss-reader)
(require 'eaf-system-monitor)
(require 'eaf-terminal)
(require 'eaf-netease-cloud-music)