Emacs被称为“神”的编辑器,在开始讲解Emacs使用前,我们首先介绍Emacs的安装。

一、windows环境下安装emacs

有三种方法:

  • 直接二进制文件包安装。
  • 安装MSYS2环境,然后通过pacman 包管理器进行安装。
  • 在MSYS2环境中,进行源代码编译安装。(推荐

1.1 二进制文件包安装

1.1.1 下载emacs及附加包

  1. 下载emacs
    地址:ftp://ftp.gnu.org/gnu/emacs/windows/
    注意有64位、32位不同的版本。这里使用64位版本。
    这里选择下载emacs-25.3_1-x86_64.zip
  2. 下载附加包
    对应于emacs-25.3_1-x86_64.zip文件,这里下载emacs-25-x86_64-deps.zip

1.1.2 安装

  1. 将下载的安装文件解压到安装目录,例如 d:\emacs25
    解压emacs-25.3_1-x86_64.zip到安装目录
    解压emacs-25-x86_64-deps.zip到同样的安装目录。
  2. 可选的依赖库
    emacs内置了对XBM、PPM/PGM/PBM图像的支持,libXpm库提供了XPM支持,这些已经包含在了上面的依赖库中。
    emacs还有很多可选功能,这需要额外的库支持。这些是在独立的依赖包中提供的。这些可选的依赖包支持一下内容:
    – 显示多种类型的内联图像(PNG、JPEG、GIF、TIFF、SVG)
    – SSL/TLS安全网络通信(https、imaps等)
    – HTML和XML解析(内置EWW浏览器所必需)
    – 压缩文本的内置解压缩
    可选的依赖库位于压emacs-25-x86_64-deps.zip中。
    新的/更新的版本位于http://msys2.github.io/或者http://sourceforge.net/projects/ezwinports/files/
    至此安装完毕。
  3. 安装命令菜单(可选,不建议安装)
    执行bin目录下你的addpm.exe

1.1.3 扩展

一些emacs特性需要一些unix工具支持,例如:

  • 拼写检查需要aspell
  • 图片缩略图预览需要ImageMagick
  • 文件比较需要diff
  • 列出指定后缀的文件需要find

有几种方法来获得这些linux工具:

  • 使用Windows Subsystem for Linux (WSL)
    at https://docs.microsoft.com/en-us/windows/wsl/about
  • 使用Cygwin(推荐)

下面简要说明:

  1. 安装WSL
    不是所有的Windows 10系统都能运行WSL,要满足两个基本要求:64位和Build号不低于14393.0(笔者使用的两个版本分别是14393.1198和14393.479)。
  2. 安装Cygwin
    见后述。

1.1.4 运行emacs

  1. GUI方式运行
    执行bin目录下的 runemacs.exe
  2. 在控制台窗口中运行
    在命令行使用下面的命令:
C:\\Users\\joe\\apps\\emacs-24.1\\bin\\emacs.exe --no-window-system

1.1.5 其他Emacs执行文件

emacs25\bin目录下有很多执行文件,说明如下:

  • emacs.exe - The main Emacs executable. As this is designed to run as both a text-mode application (emacs -nw) and as a GUI application, it will pop up a command prompt window if run directly from Explorer.
  • runemacs.exe - A wrapper for running Emacs as a GUI application without popping up a command prompt window. If you create a desktop shortcut for invoking Emacs, make it point to this executable, not to emacs.exe. If you pin Emacs to the task bar, edit the properties of the pinned shortcut (with Shift-right mouse click) to point to this executable.
  • emacsclient.exe - A command-line client program that can communicate with a running Emacs process. See the `Emacs Server’ node of the Emacs manual.
  • emacsclientw.exe - A version of emacsclient that does not open a command-line window.
  • addpm.exe - A basic installer that adds Emacs to “Start” menus and adds Emacs-related entries to the Windows Registry.
  • ctags.exe, etags.exe - Tools for generating tag files. See the `Tags’ node of the Emacs manual.
  • ebrowse.exe - A tool for generating C++ browse information. See the `Ebrowse’ manual.
    还有几个执行文件在(所版本不同,路径可能不同)相应的目录:
  • cmdproxy.exe - Used internally by Emacs to work around problems with the native shells in various versions of Windows.
  • ddeclient.exe - A tool for interacting with DDE servers. To be invoked as “ddeclient SERVER [TOPIC]”, where SERVER is the DDE server name, and sends each line of its standard input to the DDE server using the DdeClientTransaction API. This program is supposed to be invoked via the ‘call-process-region’ Emacs primitive.
  • hexl.exe - A tool for producing hex dumps of binary files. See the `Editing Binary Files’ node of the Emacs manual.
  • movemail.exe - A helper application for safely moving mail from a mail spool or POP server to a local user mailbox. See the `Movemail’ node of the Emacs manual.
  • profile.exe - A helper program that generates periodic events for profiling Emacs Lisp code.
  • update-game-score.exe - A utility for updating the score files of Emacs games.

1.2 MSYS2环境下的直接安装

1.2.1 安装和准备msys2

  1. 下载MSYS2
    从站点下载最新的msys2安装文件,其文件名为msys2-<架构>-<日期>.exe 的文件(如 msys2-x86_64-20200720.exe)。推荐从国内下载。
    https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/
    https://www.msys2.org/
  2. 安装msys2
    点击运行msys2-x86_64-20200720.exe,按照提示进行安装。这里安装到目录
    c:\msys64.
    注意,安装结束后先不运行msys2
  3. 配置msys2
    关于各种镜像站的操作:找到 c:\msys64\etc\pacman.d 文件夹,里面有三个文件: mirrorlist.mingw32 、mirrolist.mingw64 、mirrorlist.msys,分别编辑其内容为:
## mirrorlist.mingw32
##
## 32-bit Mingw-w64 repository mirrorlist
##
## 清华大学软件镜像
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
## 中科大镜像
Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/
## msys2.org
Server = http://repo.msys2.org/mingw/i686/
## Sourceforge 镜像
Server = https://sourceforge.net/projects/msys2/files/REPOS/MINGW/i686/
## The UK Mirror Service Sourceforge mirror
Server = http://sourceforge.mirrorservice.org/m/ms/msys2/REPOS/MINGW/i686/
## Sourceforge.net
Server = http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/i686
## FutureAt 镜像
Server = http://www2.futureware.at/~nickoe/msys2-mirror/msys/i686/## mirrorlist.mingw64
##
## 64-bit Mingw-w64 repository mirrorlist
##
## 清华大学软件镜像
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86\_64/
## 中科大镜像
Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86\_64/
## msys2.org
Server = http://repo.msys2.org/mingw/x86\_64/
## Sourceforge 镜像
Server = https://sourceforge.net/projects/msys2/files/REPOS/MINGW/x86\_64/
## The UK Mirror Service Sourceforge mirror
Server = http://sourceforge.mirrorservice.org/m/ms/msys2/REPOS/MINGW/x86\_64/
## Sourceforge.net
Server = http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86\_64
## FutureAt 镜像
Server = http://www2.futureware.at/~nickoe/msys2-mirror/msys/x86_64/## mirrorlist.msys
##
## MSYS2 repository mirrorlist
##
## 清华大学软件镜像
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch
## 中科大镜像
Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch
## msys2.org
Server = http://repo.msys2.org/msys/$arch
## Sourceforge 镜像
Server = https://sourceforge.net/projects/msys2/files/REPOS/msys/$arch
## The UK Mirror Service Sourceforge mirror
Server = http://sourceforge.mirrorservice.org/m/ms/msys2/REPOS/msys/$arch
## Sourceforge.net
Server = http://downloads.sourceforge.net/project/msys2/REPOS/msys/$arch
## FutureAt 镜像
Server = http://www2.futureware.at/~nickoe/msys2-mirror/msys/$arch
  1. 更新软件源
    运行msys2,然后测试以下软件源是否可用,并更新软件包数据。
pacman –Syuu
  1. 运行autorebase.bat
C:\\msys64>autorebase.bat
ReBaseImage (/usr/bin/msys-gnutls-30.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-intl-8.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-unistring-2.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-gpg-error-0.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-ffi-7.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-ksba-8.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-gcrypt-20.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-npth-0.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-p11-kit-0.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-idn2-0.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-iconv-2.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-tasn1-6.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-hogweed-6.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-gmp-10.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-assuan-0.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-nettle-8.dll) failed with last error = 2
ReBaseImage (/usr/bin/msys-gcc\_s-seh-1.dll) failed with last error = 2
The following DLLs couldn't be rebased because they were in use:
/usr/bin/msys-gnutls-30.dll
/usr/bin/msys-intl-8.dll
/usr/bin/msys-unistring-2.dll
/usr/bin/msys-gpg-error-0.dll
/usr/bin/msys-ffi-7.dll
/usr/bin/msys-ksba-8.dll
/usr/bin/msys-gcrypt-20.dll
/usr/bin/msys-npth-0.dll
/usr/bin/msys-p11-kit-0.dll
/usr/bin/msys-idn2-0.dll
/usr/bin/msys-iconv-2.dll
/usr/bin/msys-tasn1-6.dll
/usr/bin/msys-hogweed-6.dll
/usr/bin/msys-gmp-10.dll
/usr/bin/msys-assuan-0.dll
/usr/bin/msys-nettle-8.dll
/usr/bin/msys-gcc\_s-seh-1.dll
The following DLLs couldn't be rebased due to errors:
/usr/bin/msys-gnutls-30.dll
/usr/bin/msys-intl-8.dll
/usr/bin/msys-unistring-2.dll
/usr/bin/msys-gpg-error-0.dll
/usr/bin/msys-ffi-7.dll
/usr/bin/msys-ksba-8.dll
/usr/bin/msys-gcrypt-20.dll
/usr/bin/msys-npth-0.dll
/usr/bin/msys-p11-kit-0.dll
/usr/bin/msys-idn2-0.dll
/usr/bin/msys-iconv-2.dll
/usr/bin/msys-tasn1-6.dll
/usr/bin/msys-hogweed-6.dll
/usr/bin/msys-gmp-10.dll
/usr/bin/msys-assuan-0.dll
/usr/bin/msys-nettle-8.dll
/usr/bin/msys-gcc\_s-seh-1.dll

至此,MSYS2准备完毕。

1.2.2 安装emacs

先搜索一下:

pacman -Ss emacs

请根据您的操作系统的版本,选择安装相应的版本。
安装64版本:

pacman -S mingw-w64-x86\_64-emacs

安装32为版本:

pacman -S mingw-w64-i686-emacs

1.3 源代码编译安装(推荐

使用MSYS2子系统和gcc开源编译器,可以为window(7,8,10)编译安装Emacs。
对于高级用户,例如需要使用Emacs来支持pdf、图片、编程开发等功能的用户,推荐此种方案。

1.3.1 安装和准备MSYS2编译环境

安装和准备MSYS2见前面一节的描述。

1.3.2 准备Emacs编译环境

然后,安装emacs编译所需的软件包:

pacman -Sy --noconfirm base-devel git mingw-w64-x86\_64-{giflib,gnutls,jansson,zlib,lib{jpeg-turbo,png,rsvg,tiff,xml2},toolchain,xpm-nox}

要支持xwidget浏览器:(这里不使用)

pacman –Sy webkitgtk

1.3.3 获取emacs源文件

为了简化安装,可以定义环境变量 BUILDDIR(存放二进制执行文件)、INSTALLDIR(存在安装目标文件路径)、SOURCEDIR(存放源文件)。注意:因为在MSYS2子系统中操作,所以路径名要用正斜杠(“/”)。下面的命令创建SOURCEDIR,运行autogen.sh脚本创建一个配置脚本。

  1. 建立SOURCE目录
SOURCEDIR=/var/git/emacs && mkdir -p $SOURCEDIR && cd $SOURCEDIR
  1. 获取源文件。
    可以从http://git.savannah.gnu.org/cgit/emacs.git/refs/tags
    选择一个合适版本的源代码。或者直接从git仓库克隆。
git clone git://git.savannah.gnu.org/emacs.git . --depth=1

当前目录克隆Emacs项目。有一点不得不提,Gti自动改换行符的功能(autocrlf)很讨厌,下面的命令关掉它:

git config core.autocrlf false
  1. 运行autogen.sh脚本创建一个配置脚本
./autogen.sh

上述步骤可以使用一个命令搞定:

SOURCEDIR=/var/git/emacs && mkdir -p $SOURCEDIR && cd $SOURCEDIR &&
git clone git://git.savannah.gnu.org/emacs.git . --depth=1 &&
./autogen.sh

1.3.4 更新、编译和安装EMACS

  1. 更新软件源
    如果是从Git仓储下载,可以更新一下:
SOURCEDIR=/var/git/emacs && cd $SOURCEDIR
git reset --hard HEAD
git fetch
git checkout origin/master
  1. 清空和/或创建BUILDDIR
BUILDDIR=/d/emacs && rm -rf $BUILDDIR &>/dev/null
mkdir -p $BUILDDIR; cd $BUILDDIR
  1. 配置和编译emacs
SOURCEDIR=/var/git/emacs && $SOURCEDIR/configure --without-dbus
--without-compress-install --with-modules 'CFLAGS=-O2 -g3'

可选项说明:

  • –without-dbus: windows版本的emacs并不支持D-Bus选项,因此这里进行了禁用。
  • –without-compress-install: 使emm能够浏览图片
  • –with-modules:支持模块
  • ‘CFLAGS=-O2 -g3’ 编译选项
    另外,’–prefix’ 选项定义了编译输出二进制文件的存储位置。后面‘make install’将会使用,这里没有采用这个选项,因为我们在make install命令中直接进行了定义。

进行编译:

make
  1. 安装stripped版本Emacs到INSTALLDIR
INSTALLDIR=/d/SoftTools/dev-tools/emacs && make install-strip prefix=$INSTALLDIR

上述步骤可以使用一个命令搞定:

SOURCEDIR=/var/git/emacs INSTALLDIR=/d/SoftTools/dev-tools/emacs BUILDDIR=/d/emacs && pushd $SOURCEDIR && git reset --hard HEAD && git fetch && git checkout origin/master && rm -rf $BUILDDIR &>/dev/null &&  mkdir -p $BUILDDIR; pushd $BUILDDIR && $SOURCEDIR/configure --without-dbus --without-compress-install --with-modules 'CFLAGS=-O2 -g3' && make –j4 && make install-strip prefix=$INSTALLDIR

如果已经安装了MSYS2,只需要重复这一步来更新emacs到最新版本。
安装完毕后,可通过命令查看配置特性和选项:
运行emacs,输入:

C-h v system-configuration-features
C-h v system-configuration-options

  1. 清理
    按照上面的步骤安装后,会遗留下源文件、编译过程文件。
    编译完成后,建议清除编译过程文件。也就是/d/emacs 目录。如果长期不用,可以删除。

1.3.5 可选:拷贝必须要的二进制文件

因为我们编译的时候用了很多由第三方库提供的功能, 所以我们编译的这个Emacs是需要那些DLL才能运行的。如果你的系统里面MSYS2已经被添加到PATH环境变量里(例如PATH里包含了C:\msys2\mingw64\bin)了,那这将不是问题,但如果环境变量里没有或者你想在其他电脑上用,需要用下面的命令复制所需的DLL到Emacs所在目录:

INSTALLDIR=c:/programs/emacs
cp /mingw64/bin/{zlib\\\*,lib{winpthread-\\\*,Xpm-noX\\\*,gomp-\\\*,gcc\\\_s\\\_seh-\\\*,glib-\\\*,intl-\\\*,iconv-\\\*,gobject-\\\*,ffi-\\\*,gio-\\\*,gmodule-\\\*,freetype-\\\*,pixman-\\\*,png\\\*,expat-\\\*,harfbuzz-\\\*,gnutls-\\\*,gnutlsxx-\\\*,tiff-\\\*,tiffxx-\\\*,jpeg-\\\*,gif-\\\*,bz2-\\\*,jbig-\\\*,gmp-\\\*,hogweed-\\\*,nettle-\\\*,p11-kit-\\\*,tasn1-\\\*}}.dll $INSTALLDIR/bin

注意:
1)windows、msys2下都有find命令,最好在emacs中配置可执行文件路径。
2)如果没有设置上述路径,不能支持SSL、图形处理等,因为它们依赖于支持库。

1.3.4 Plugin

安装PDF Tools 和Xwidgets web browser 插件,具体操作,请见:
http://tuhdo.github.io/setup-emacs-windows.html

1.4 Emacs配置文件位置

跟以前使用的 Emacs for MS Win64 一样,emacs 配置文件还是默认在C:/Users/AppData/Roaming/.emacs.d 中。大多数 package 放在本地c:/msys2/home/user/.emacs.d/elpa/yourdir/以后使用 (add-to-list 'exec-path “yourdir”) 即可正常调用。

1.4.1 定制化配置文件的位置

对于 Windows 10, Windows 8, Windows 7, Windows Vista,默认加载的配置文件是以下二者之一:

  • %HOMEPATH%\AppData\Roaming\.emacs
  • %HOMEPATH%\AppData\Roaming\.emacs.d\init.el

也可以指定加载的配置文件:

%home%\\apps\\emacs-24.1\\bin\\runemacs.exe -q --load=%home%\\ErgoEmacs\_dev\\init.el --load=%home%\\.emacs

另外,可以在windows中设置环境变量HOME,使其不默认指向 %HOMEPATH%\AppData\Roaming\,但带来的负面影响是改变了msys2中的默认HOME目录。不建议采用。

1.5 主要参考链接:

  • http://git.savannah.gnu.org/cgit/emacs.git/tree/nt/INSTALL.W64
  • Compiling WordNet on Windows to use with Emacs
  • zsh shell inside Emacs on Windows
  • It’s about the journey: Compiling 64-bit Unison / GTK2 on Windows
  • MSYS2 - successful successor of MSYS ?
  • git on Windows - location of configuration files

二、linux环境下安装

这里以ubuntu 为例进行介绍。其安装方法有两种:

  • 使用发行包进行安装
  • 源代码编译安装

2.1 使用发行包进行安装

发行源仓库中的emcas一般是较新的稳定版本,而且linux的不同版本所安装的emacs版本也不相同。Ubuntu自身的安装源仓库的emacs版本较低,为了安装较新的emacs需要从其他发行源进行安装。
在ubuntu 1604上的安装如下:

  1. 添加发行源
sudo add-apt-repository ppa:ubuntu-elisp/ppa
sudo apt-get update
  1. 执行安装
sudo apt-cache search emacs
sudo apt-get install emacs-snapshot emacs-snapshot-el
  1. 安装完成以后,可以将PPA源仓库删除:
sudo add-apt-repository -r ppa:ubuntu-elisp/ppa
sudo apt-get update

说明,在不同的版本上,emacs的发行源仓库的地址可能会有所不同。例如,在ubuntu 1804上,其发行源为:ppa:kelleyk/emacs

2.2 源代码编译安装(推荐)

可以使用源代码方式安装最新版本的emacs。

2.2.1 下载和解压emacs源代码

  1. 下载emacs源代码
    下载地址:http://ftp.gnu.org/pub/gnu/emacs/
    选择一个合适的版本进行下载,这里下载emacs-25.1.tar.gz。
    也可以直接从git仓库中下载最新的emacs:
$ git clone http://repo.or.cz/r/emacs.git
  1. 解压缩
$ tar xvzf emacs-25.1.tar.gz

2.2.2 安装编译所需的支持包(这里选用的gtk图形库)

  1. 安装基础软件包,主要安装GTK3以使用true type fonts。这里安装了xorg、gtk等支持包。
    对于 64位OS:
$ sudo apt-get build-dep emacs24 xserver-xorg-dev xorg-dev lib64ncurses5 lib64ncurses5-dev libidl.dev libgtk-3-dev libgtk2.0-dev libgnutls-dev
  1. 安装图形支持库
$ sudo apt-get install libpng12-dev libjpeg-dev libtiff5-dev libgif-dev librsvg2-dev libxpm-dev
$ sudo apt-get install libncurses5-dev

安装libncurses5-dev是因为部分图形库依赖于它。

  1. 安装文本和字体支持,以支持web浏览。
$ sudo apt-get install libm17n-dev libxml2-dev

说明:也可以使用aptitude安装,这样可以解决包依赖问题。

sudo aptitude install libgtk2.0-dev
  1. 安装其他扩展字体(可选)
    如果要安装其它扩展字体,可以从下列网址下载相应的字体并安装。
    https://www.gnu.org/software/freefont
  2. 如果需要支持xwindget浏览器,需要下面的依赖包(可选)
sudo apt-get install webkitgetk

2.2.3 编译安装

  1. 配置
cd ~/emacs-&lt;version>\*
$ ./autogen.sh
$ ./configure --prefix=/usr/local/emacs --enable-font-backend
--with-xft --with-freetype --with-x-toolkit=gtk

参数解释:

  • –prefix=/usr/local/emacs24 指定emacs安装目录,默认为/usr/local
  • –enable-font-backend 让emacs支持雅黑字体
  • –with-freetype 支持freetype字体
  • –with-x-toolkit=gtk 指定环境为gtk

如果仅仅支持文本终端方式,可以使用:

./configure --without-x \[--prefix=/path/to/dir\]

如果支持xwidget,添加选项:

–with-xwidgets --with-x --with-modules

  1. 没有错误的化,则继续编译
./make -j4
  1. 编译完成后,试运行一下程序:
./src/emacs -Q
  1. 创建一个目录,将emacs安装在这里
mkdir /usr/local/emacs
./sudo make install
  1. 清理一下
./make clean
./make distclean

2.2.3 建立图标和链接

  1. 创建链接
    安装完后要在/usr/local/bin做一个链接(因为/usr/local/emacs/bin/不在PATH变量中)
cd /usr/local/bin
sudo ln -s /usr/local/emacs/bin/\* ./
  1. 创建emacs的图标
    进入应用目录:
cd /usr/local/emacs/share/applications

把下面这个文件复制到

cp emacs.desktop /usr/share/applications/

之后注销重新登录一下就可以找到图标了

  1. 建立emacs别名
    加入下列语句到.bashrc或者.zshrc当中。

alias em=‘emacs’

2.2.4 配置及扩展组件安装

1、交换Caplock和Control 键
放置下面的内容到shell 初始化文件(.bashrc或者.zshrc)中。

/usr/bin/setxkbmap -option “ctrl:swapcaps”

进一步的参考请见 http://askubuntu.com/a/412622/13847

三、Emacs的配置文件参考

根据用途的不同,可以按需进行Emacs配置,使其能够进行文本编辑、各种代码的编辑编译测试,以及安装或自开发扩展软件包并加以配置,实现随心所欲使用Emacs的目标。
下面个人Windows环境下的emacs配置文件,供参考。
.emacs.d\init.el文件内容如下:

;; Set repositories
(require 'package)
(setq-defaultload-prefer-newer tpackage-enable-at-startup nil)
(add-to-list 'package-archives '("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/") t)
;; (add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/") t)
;; (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)
;; Install dependencies
(unless (package-installed-p 'use-package)(package-refresh-contents)(package-install 'use-package))
(setq-defaultuse-package-always-defer tuse-package-always-ensure t)
(setenv "PATH" (concat "C:\\msys64\\usr\\bin;C:\\msys64\\mingw64\\bin;" (getenv "PATH")))
(set-language-environment 'utf-8)
(setq locale-coding-system 'utf-8)
;; (set-default-coding-systems 'utf-8)   ;使能该条,编辑中文时运行会很卡。
(set-terminal-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; this variables must be set before load custom setup files
(add-to-list 'load-path "~/.emacs.d/custom")
(require 'setup-face)
(require 'setup-editing)

.emacs.d\custom\setup-face.el文件内容如下:

;; Start maximised (cross-platf)
(add-hook 'window-setup-hook 'toggle-frame-maximized t)
(when window-system(blink-cursor-mode 0)                           ; Disable the cursor blinking(scroll-bar-mode 0)                             ; Disable the scroll bar(tool-bar-mode 0)                               ; Disable the tool bar(tooltip-mode 0))                               ; Disable the tooltips
(setq-defaultad-redefinition-action 'accept                   ; Silence warnings for redefinitionconfirm-kill-emacs 'yes-or-no-p                  ; Confirm before exiting Emacscursor-in-non-selected-windows t                 ; Hide the cursor in inactive windowsdelete-by-moving-to-trash t                      ; Delete files to trashdisplay-time-default-load-average nil            ; Don't display load averagedisplay-time-format "%H:%M"                      ; Format the time stringfill-column 80                                   ; Set width for automatic line breakshelp-window-select t                             ; Focus new help windows when openedindent-tabs-mode nil                             ; Stop using tabs to indentinhibit-startup-screen t                         ; Disable start-up screeninitial-scratch-message ""                       ; Empty the initial *scratch* bufferleft-margin-width 1 right-margin-width 1         ; Add left and right marginsmode-require-final-newline 'visit                ; Add a newline at EOF on visitmouse-yank-at-point t                            ; Yank at point rather than pointerns-use-srgb-colorspace nil                       ; Don't use sRGB colorsrecenter-positions '(5 top bottom)               ; Set re-centering positionsredisplay-dont-pause t                           ; don't pause display on inputdebug-on-error tjit-lock-defer-time 0frame-resize-pixelwise tfast-but-imprecise-scrolling tscroll-conservatively 10000                      ; Always scroll by one linescroll-margin 1                                  ; scroll N lines to screen edgescroll-step 1                                    ; keyboard scroll one line at a timescroll-preserve-screen-position 1select-enable-clipboard t                        ; Merge system's and Emacs' clipboardsentence-end-double-space nil                    ; End a sentence after a dot and a spaceshow-trailing-whitespace nil                     ; Display trailing whitespacessplit-height-threshold nil                       ; Disable vertical window splittingsplit-width-threshold nil                        ; Disable horizontal window splittingtab-width 4                                      ; Set width for tabsuniquify-buffer-name-style 'forward              ; Uniquify buffer nameswindow-combination-resize t                      ; Resize windows proportionallyx-stretch-cursor t)                              ; Stretch cursor to the glyph width
(delete-selection-mode)                           ; Replace region when inserting text
(setq line-number-mode t)                         ; Enable line numbers in the mode-line
(setq column-number-mode t)                       ; Enable column numbers in the mode-line
(size-indication-mode 1)                          ; Enable size status in the mode-line
(display-time-mode)                               ; Enable time in the mode-line
(fringe-mode 0)                                   ; Hide fringes
(fset 'yes-or-no-p 'y-or-n-p)                     ; Replace yes/no prompts with y/n
(global-hl-line-mode)                             ; Hightlight current line
(show-paren-mode t)
;;(setq show-paren-style 'expression)
(global-subword-mode)                             ; Iterate through CamelCase words
(menu-bar-mode 0)                                 ; Disable the menu bar
;(mouse-avoidance-mode 'banish)                    ; Avoid collision of mouse with point
(put 'downcase-region 'disabled nil)              ; Enable downcase-region
(put 'upcase-region 'disabled nil)                ; Enable upcase-region
(setq frame-title-format                ;set the frame title name '("" invocation-name " - " (:eval (if (buffer-file-name)(abbreviate-file-name (buffer-file-name))"%b"))))
;; customize fontset(setq w32-charset-info-alist(cons '("gbk" w32-charset-gb2312 . 936) w32-charset-info-alist))
(create-fontset-from-fontset-spec"-outline-Source Code Pro-normal-normal-normal-mono-15-*-*-*-c-*-fontset-gbk")
(setq w32-enable-synthesized-fonts t)              ; Enable bold and italic fonts
;; (set-face-font 'italic "-*-Source Code Pro-normal-i-*-*-15-*-*-*-c-*-fontset-gbk")
(set-face-font 'bold "-*-Source Code Pro-bold-*-*-*-15-*-*-*-c-*-fontset-gbk")
(set-fontset-font"fontset-default" nil"-outline-新宋体-normal-normal-normal-mono-*-*-*-*-c-*-iso10646-1" nil 'prepend)
(set-fontset-font"fontset-gbk" 'kana"-outline-新宋体-normal-normal-normal-mono-*-*-*-*-c-*-iso10646-1" nil 'prepend)
(set-fontset-font"fontset-gbk" 'han"-outline-新宋体-normal-normal-normal-mono-*-*-*-*-c-*-iso10646-1" nil 'prepend)
(set-fontset-font"fontset-gbk" 'cjk-misc"-outline-新宋体-normal-normal-normal-mono-*-*-*-*-c-*-iso10646-1" nil 'prepend)
(set-fontset-font"fontset-gbk" 'symbol"-outline-新宋体-normal-normal-normal-mono-*-*-*-*-c-*-iso10646-1" nil 'prepend)
(add-to-list 'default-frame-alist '(font . "fontset-gbk"))
(set-default-font "fontset-gbk")
;;(defvar mp/font-family            "Consolas"  "The font to use.")
(defvar mp/font-size-default      100       "The font size to use for default text.")
(defvar mp/font-size-header-line  100       "The font size to use for the header-line.")
(defvar mp/font-size-mode-line    90       "The font size to use for the mode-line.")
(defvar mp/font-size-title        100       "The font size to use for titles.")
(use-package solarized-theme:demand t:config(load-theme 'solarized-wombat-dark t);; (load-theme 'solarized-dark t)        ;; (load-theme 'solarized-light t)(set-face-attribute 'font-lock-comment-face nil :italic t)(set-face-attribute 'font-lock-doc-face nil :italic t);; (set-face-attribute 'default nil :height mp/font-size-default :font mp/font-family)(set-face-attribute 'header-line nil :height mp/font-size-header-line)(set-face-attribute 'mode-line nil :height mp/font-size-mode-line)(set-face-attribute 'mode-line-inactive nil :height mp/font-size-mode-line);; make the modeline high contrast(setq solarized-high-contrast-mode-line t);; make the fringe stand out from the background(setq solarized-distinct-fringe-background t)
)
(provide 'setup-face)

.emacs.d\custom\setup-editing.el文件内容如下:

(add-hook 'focus-out-hook #'garbage-collect)
;; (setq-default custom-file (expand-file-name "custom.el" user-emacs-directory))
;; (when (file-exists-p custom-file)
;;   (load custom-file))
;; (let ((secret.el (expand-file-name "secret.el" "~/emax/")))
;;   (when (file-exists-p secret.el)
;;     (load secret.el)))
;; (use-package mdi
;;   :ensure nil
;;   :load-path "~/emax/lisp/mdi/"
;;   :after solarized-theme)
(global-set-key (kbd "M-o") 'other-window)
(global-set-key (kbd "RET") 'newline-and-indent)
;; (setq require-final-newline t)
;; (setq recentf-max-saved-items 2048)
;; (add-hook 'before-save-hook 'delete-trailing-whitespace)
;; (setq browse-url-browser-function 'browse-url-default-browser)
(defun choose-browser (url &rest args)(interactive "sURL: ")(if (y-or-n-p "Use external browser? ")(browse-url-default-browser url)(w3m-browse-url url)))
(setq browse-url-browser-function 'choose-browser)
;; define markdown transform program
(setq markdown-command "d:\\SoftTools\\dev-tools\\pandoc\\pandoc.exe")
;; Running Windows Powershell from within Emacs
; (setq explicit-shell-file-name "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe")
; (setq explicit-powershell.exe-args '("-Command" "-" )) ; interactive, but no command prompt
; (autoload 'powershell "powershell" "Run powershell as a shell within emacs." t)
;; (pdf-tools-install :no-query)
(provide 'setup-editing)

四、FAQ

4.1 elpa签名过期

临时禁止校验签名:

(setq package-check-signature nil)

更新GPG kering

M-x package-install RET gnu-elpa-keyring-update RET

参考:http://elpa.gnu.org/packages/gnu-elpa-keyring-update.html

4.2 melpa无法连接

为了快捷,可以使用国内的镜像:

(setq package-archives '(
;; uncomment below line if you need use GNU ELPA ;;
;;("gnu" . "https://elpa.gnu.org/packages/")
;;("localelpa" . "~/.emacs.d/localelpa/")
;; ;; {{ 163 repository:
;; ("melpa" . "https://mirrors.163.com/elpa/melpa/")
;; ("melpa-stable" . "https://mirrors.163.com/elpa/melpa-stable/")
;; ;; }}
;; ;; {{ tinghua repository (more stable than 163, recommended)
;; ;;See https://mirror.tuna.tsinghua.edu.cn/help/elpa/ on usage:
;; ("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
;;("melpa-stable" .
"http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa-stable/")
;; ;; ("org" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/org/")
;; }}
;;("melpa" . "https://melpa.org/packages/")
;;("melpa-stable" . "https://stable.melpa.org/packages/")
))

4.3 替换ubuntu ppa的源

  1. 备份原来的源
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  2. 选择正确的源,注意版本的系统代号:
    Ubuntu 12.04 (LTS)代号为precise。
    Ubuntu 14.04 (LTS)代号为trusty。
    Ubuntu 15.04 代号为vivid。
    Ubuntu 15.10 代号为wily。
    Ubuntu 16.04 (LTS)代号为xenial。
    Ubuntu 18.04 (LTS)代号为bionic。
    编辑soruces.list文件,进行修改:
sudo vim /etc/apt/sources.list

替换为以下内容:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

  1. 基本操作

执行更新:

sudo apt-get update

复损坏的软件包,尝试卸载出错的包,重新安装正确版本的:

sudo apt-get -f install

更新软件:

sudo apt-get upgrade

完!

(一)安装Emacs相关推荐

  1. Windows中安装Emacs

    为什么80%的码农都做不了架构师?>>>    "在这个蔚蓝色的星球上,流传着两大神器的传说:据说Emacs是神的编辑器,而Vim是编辑器之神." 既然有人这么说 ...

  2. win10安装emacs+spacemacs,建议用官方安装方式

    1.下载emacs最新版 26.1 官网下载地址:https://www.gnu.org/software/emacs/download.html#nonfree 2.解压emacs到你的安装目录,我 ...

  3. CentOS安装EMACS文件夹树型图插件与颜色插件

    2019独角兽企业重金招聘Python工程师标准>>> 我的EMACS是CentOS7自带的,版本号24.3. 依照https://www.emacswiki.org/emacs/S ...

  4. linux emacs 编译,linux 编译安装emacs和安装spacemacs

    下载 wget http://mirrors.ustc.edu.cn/gnu/emacs/emacs-25.1.tar.xz tar xvf emacs-25.1.tar.xz 编译安装 ./conf ...

  5. Mac下安装emacs+cscopse+auto-complete

    第一种方式:安装cscope # sudo apt install cscope 第二种方式:下载cscope和auto-complete  下载 2.安装: # tar -zxf cscope-xx ...

  6. ubuntu安装emacs

    1.查看版本 emacs --version 2.卸载 sudo apt remove --autoremove emacs26 emacs26-nox 3.安装 sudo add-apt-repos ...

  7. windows7 安装Emacs 24

    最近因为需要开发windows上的产品,又回到windows上来,因为要写newlisp脚本,还是emacs用起来比较方便. 下面介绍一下安装最新版本的emacs的步骤, 1. 从http://cor ...

  8. Linux下安装Emacs

    笔者VM下安装的Redhat 下载emacs-23.1.tar.gz http://ftp.gnu.org/pub/gnu/emacs/emacs-23.1.tar.gz cd /opt     // ...

  9. ubuntu16.04下安装emacs

    1.直接在软件中心下载. 2.终端下载: 依次输入这三条命令即可 sudo add-apt-repository ppa:ubuntu-elisp/ppa sudo apt-get update su ...

  10. linux emacs 编译,CentOS编译安装emacs并配置

    C#子类调用基类构造备忘 using System; using System.Collections.Generic; using System.Linq; using System.Web; na ...

最新文章

  1. [转载]SQL注入***之 mysql_set_charset(版本要求p
  2. Altium Designer PCB快速布局
  3. python【蓝桥杯vip练习题库】ADV-281特等奖学金
  4. python不想学了-十分钟也学不会python?就不要学python了
  5. 数据中心大火波及360万网站,或因UPS故障,3月10日晚法国斯特拉斯堡
  6. html.编辑数据回显,从HTML表格编辑/更新MySQL数据库值
  7. 不能使用缺陷数据作为绩效度量
  8. 剑指offer之反转链表
  9. 苹果php环境,苹果电脑安装PHP环境步骤-PHP问题
  10. c语言教程for,C语言菜鸟基础教程之for循环
  11. (秒杀项目) 4.6 分布式状态管理
  12. 最新Activity与Fragment完全理解
  13. TM2008 Preview体验
  14. 被欧美公司垄断的工业软件,中国还有机会吗?
  15. SumatraPDF的反向搜索
  16. python OpenCV与NAOqi库在机器人点球比赛中的应用
  17. 三个团队的站立会议旁观笔记
  18. ssm毕设项目住院病人管理系统pebfh(java+VUE+Mybatis+Maven+Mysql+sprnig)
  19. ajax的各个参数详细讲解
  20. springboot集成spring-boot-starter-data-elasticsearch

热门文章

  1. BZOJ 3162 / Luogu P4895: 独钓寒江雪 树hash+DP
  2. Flink写入hdfs报错:Flink job failed with “Checkpoint Coordinator is suspending
  3. 如何有效投诉中国电信、中国联通、中国移动?
  4. python 英语拼写-Python实现单词拼写检查
  5. 美团校招php笔试题,2018 美团校招笔试题详解
  6. (sn0wbreeze保基带升级,redsnow,absinthe越狱)常用越狱工具下载:redsnow,absinthe,tinyumbrella,sn0wbreeze
  7. 【HDU 杭电 5773 The All-purpose Zero】
  8. 推荐一个好用的搜索微信公众号文章的搜索引擎
  9. 有哪些资本运作的经典案例?
  10. java web前端邮件,JavaMail:在Web应用上完整接收、解析复杂邮件(转)