Emacs有很多强大的插件,但是插件安装多了会导致启动速度很慢。为了解决这个问题,一个方法是使用emacs提供的server模式。

基本用法[1]

  • 启动emacs server:
$ emacs --daemon
  • 编辑文件
$ emacsclient file
$ emacsclient -t file # 字符界面
$ emacsclient -c file # GUI界面

添加命令行别名

为了方便在终端上使用,在~/.bashrc文件中加入如下两行:

alias ec='emacsclient -t -a ""'
alias sec='sudo emacsclient -t -a ""'

其中-a表示alternative-editor,用于指定无法连接emacs server时使用的编辑器。空字符串有特殊意义,表示先启动emacs server,再重新连接。

若只有第一行,执行sudo ec file会找不到命令,因为root用户并没有定义ec别名。因此定义sec,作为ec的sudo版本。

添加到文件管理器,设为默认编辑器

接下来我们希望双击文本文件时也能够使用emacsclient。创建~/.local/share/applications/emacsclient.desktop

[Desktop Entry]
Name=Emacs (Client)
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=emacsclient -c -a "" %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;Utility;
StartupWMClass=Emacs

选择打开方式为Emacs (Client)即可。

给命令行和GUI设置不同的theme (可选)

最后还要处理一个比较细节的问题,终端和GUI版本使用同一套主题可能会有问题。然而遗憾的是,emacs的主题是全局的,无法给frame单独设置,因此只能采取一些取巧的方法。

  • 解决方法1:

    第一种方法是当创建一个新frame时,根据frame的类型,手动调整它的样式。例如[2]:
(defun setup-window-system-frame-colours (&rest frame)
(if window-system
(let ((f (if (car frame)
(car frame)
(selected-frame))))
(progn
(set-frame-font "Bera Sans Mono-11")
(set-face-background 'default "#232F2F" f)
(set-face-foreground 'default "#FFFFFF" f)
(set-face-background 'fringe "#000000" f)
(set-face-background 'cursor "#2F4F4F" f)
(set-face-background 'mode-line "#2F4F4F" f)
(set-face-foreground 'mode-line "#BCBf91" f))))) (require 'server)
(defadvice server-create-window-system-frame
(after set-window-system-frame-colours ())
"Set custom frame colours when creating the first frame on a display"
(message "Running after frame-initialize")
(setup-window-system-frame-colours))
(ad-activate 'server-create-window-system-frame)
(add-hook 'after-make-frame-functions 'setup-window-system-frame-colours t)
  • 解决方法2:

    第2种方法类似,根据frame的类型,应用或者取消主题[3]。
(load-theme 'monokai t t)
(defun on-frame-open (frame)
;; (select-frame frame)
(if (display-graphic-p frame)
(enable-theme 'monokai)
(disable-theme 'monokai))) (add-hook 'after-make-frame-functions 'on-frame-open)

参考资料

1 https://www.emacswiki.org/emacs/EmacsClient

2 https://www.emacswiki.org/emacs/SettingFrameColorsForEmacsClient

3 https://emacs.stackexchange.com/questions/2096/different-themes-for-terminal-and-graphical-frames-when-using-emacs-daemon

Emacs服务器模式以及emacsclient配置的更多相关文章

  1. CentOS 6 搭建SVN支持httpd和svnserve独立服务器两种模式 以及邮件配置

    Linux下SVN服务器同时支持Apache的http和svnserve独立服务器两种模式且使用相同的访问权限账号 服务器操作系统:CentOS 6.x 1.在服务器上安装配置SVN服务: 2.配置S ...

  2. Citrix 服务器虚拟化之五 Xenserver配置存储

    Citrix 服务器虚拟化之五  Xenserver配置存储 XenServer中定义了一个容器称为存储库(SR)来描述一个特定的存储目标存储虚拟磁盘映像(VDI). VDI是一个的磁盘抽象,包含一个 ...

  3. CentOS 6.3下rsync服务器的安装与配置[转]

    CentOS 6.3下rsync服务器的安装与配置   一.rsync 简介 Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件,也 ...

  4. Linux - CentOS6.5服务器搭建与初始化配置详解(下)

    传送带:Linux - CentOS6.5服务器搭建与初始化配置详解(上) 继续接着上面的安装,安装完后会出现下面界面 点击reboot重启 重启后可以看到下面的tty终端界面  因为这就是最小化安装 ...

  5. MySQL服务器的安装和配置,MySQL Workbench 8.0.12安装,MySQL的基本使用

    一 MySQL服务器的安装和配置 二 MySQL Workbench 8.0.12安装 三 MySQL的基本使用 一MySQL服务器的安装和配置 MySQL是目前最为流行的开放源码的数据库,是完全网络 ...

  6. Linux下NAT模式和桥接模式的网络配置

        Linux下NAT模式和桥接模式的网络配置 最近在配置linux虚拟机的时候发现有很多坑,现在记录下来以防日后又跳到坑里. 我的运行环境是:主机 windows 7  虚拟机 Virtualb ...

  7. [同事转帖] .net core的服务器模式和工作站模式

    发现自己的服务器上面的进程占用越来越厉害 所以就跟同事讨论了一下 性能组同事 说已经发现 并且给了一个 网址 这里转帖记录一下 避免以后找不到. .NET Core是一个开源通用的开发框架,具有跨平台 ...

  8. Apache服务器的安装与配置

    文档:http://httpd.apache.org/docs/2.4/ 指令:http://httpd.apache.org/docs/2.4/mod/core.html 一.配置文件 语法 * 主 ...

  9. Solr系列二:solr-部署详解(solr两种部署模式介绍、独立服务器模式详解、SolrCloud分布式集群模式详解)

    一.solr两种部署模式介绍 Standalone Server 独立服务器模式:适用于数据规模不大的场景 SolrCloud  分布式集群模式:适用于数据规模大,高可靠.高可用.高并发的场景 二.独 ...

随机推荐

  1. 微信小程序 画布arc截取圆形图片

    画布提供了一种可以创建圆的方法 arc(x, y, r, s, e, counterclockwise) x,y:圆心 r:圆的半径 s:起始弧度 (0) e:终止弧度 (1.5 * Math.PI) ...

  2. 【剑指Offer面试编程题】题目1510:替换空格--九度OJ

    题目描述: 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 输入: 每个 ...

  3. Day9 - A - Apple Catching POJ - 2385

    Description 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速移动到另外一棵APP树下接APP(移动时间可 ...

  4. Java面向对象之类、接口、多态

    Java面向对象之类.接口.多态 类 class Person { // 实例属性 int age; String name; // 类属性 static int v = 1; // 构造器 publ ...

  5. 常用mac/unix/linux命令

    1.查询ip地址 ifconfig 2.查找服务器上应用程序的端口分配 grep telnet /etc/services (telnet) telnet使用TCP/UDP端口号23 grep dom ...

  6. Spring JMSTemplate 与 JMS 原生API比较

    博客分类: JMS Spring 2.x   JMSUtil与Spring JmsTemplate的对比 Author:信仰 Date:2012-4-20 未完待续,截止日期2012-4-20 从以下 ...

  7. dataset的reparation和coalesce

    /** * Returns a new Dataset that has exactly `numPartitions` partitions, when the fewer partitions * ...

  8. 配置antMatchers(HttpMethod.GET,"/**").permitAll()当时仍然会校验

    .antMatchers(HttpMethod.GET,"/**").permitAll() .anyRequest().authenticated() .and() .addFi ...

  9. [转载]@Component 和 @Bean 的区别

    @Component 和 @Bean 的区别 @Component 和 @Bean 的区别 Spring帮助我们管理Bean分为两个部分,一个是注册Bean,一个装配Bean. 完成这两个动作有三种方 ...

  10. 第四张5G牌照发给广电,能打破三大运营商的垄断吗?

    近段时间,多个国家处于莫须有的安全性考虑,禁止华为参与核心5G网络设备竞标.其实这就从侧面反映出,国内民族企业在5G层面的领先性.当然,这也让我们认知到,5G网络将是新时代的竞争关键节点.为此,国内正 ...