博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
工欲善其事,必先利其器之—MAC下安装与配置emacs
阅读量:4029 次
发布时间:2019-05-24

本文共 6022 字,大约阅读时间需要 20 分钟。

安装应用

mac os下安装emacs有如下方式

* 通过安装

brew install emacs --with-cocoa
  • 通过安装
sudo port install emacs-app
  • 通过下载安装包
    这里写图片描述

注:这里建议于第三种方式安装,根据以住的经验兼容性问题会少很多!

环境配置

命令环境

在.bash_profile文件添加如下代码,方便使用emas打开文件

# for emcas# export EDITOR="emacsclient -n "# alias e="emacsclient -n# /Applications/Emacs.app/Contents/MacOS/binEMACS_HOME=/Applications/Emacs.app/Contents/MacOS# 在终端下打开文件,替换命令行默认的emacsalias emacs="${EMACS_HOME}/Emacs -nw"# GUI方式打开文件alias e="${EMACS_HOME}/bin/emacsclient -n"

如下在命令行下没有替换系统emacs的使用,用–version可以看到是系统自动的

luogw@luogw-MacBook-Pro channel_template$ emacs --versionGNU Emacs 22.1.1Copyright (C) 2007 Free Software Foundation, Inc.GNU Emacs comes with ABSOLUTELY NO WARRANTY.You may redistribute copies of Emacsunder the terms of the GNU General Public License.For more information about these matters, see the file named COPYING.

替换系统emacs的使用后(在.bash_profile中添加alias emacs=”${EMACS_HOME}/Emacs -nw” 并source .bash_profile)

luogw@luogw-MacBook-Pro ~$ emacs --versionGNU Emacs 26.1Copyright (C) 2018 Free Software Foundation, Inc.GNU Emacs comes with ABSOLUTELY NO WARRANTY.You may redistribute copies of GNU Emacsunder the terms of the GNU General Public License.For more information about these matters, see the file named COPYING.

.emacs

;;==============================================================;; base configure for common using;;=============================================================;; start server , 这样在终端下主可以通过emacsclient -n 直接于GUI emacs打开文件(require 'server)(unless (server-running-p "server")(server-start));; Added by Package.el.  This must come before configurations of;; installed packages.  Don't delete this line.  If you don't want it,;; just comment it out by adding a semicolon to the start of the line.;; You may delete these explanatory comments.(package-initialize)(require 'package)(add-to-list 'package-archives             '("melpa-stable" . "https://stable.melpa.org/packages/"))(package-initialize);; package server;; (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/");; ("melpa-stable" . "https://stable.melpa.org/packages/")));; (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/");; ("melpa-stable" . "https://stable.melpa.org/packages/");; ("marmalade" . "http://marmalade-repo.org/packages/");; ("melpa" . "http://melpa.milkbox.net/packages/")));; background color , 苹果绿,爱护眼睛(when window-system  (custom-set-faces   '(default ((t (:background "#B4EEB4"))))));; copy content from elsewhere to emacs or emacs copied to other places(setq x-select-enable-clipboard t);; show line number(require 'linum)(global-linum-mode t);; kill current buffer(global-set-key (kbd "C-x k") (lambda () (interactive) (kill-buffer (current-buffer))));; open .emacs(global-set-key (kbd "M-h") (lambda () (interactive) (find-file "~/.emacs")))(blink-cursor-mode nil);; hide memubar,false;;(menu-bar-mode -1);; hide toolbar,false(tool-bar-mode -1);; show file path in window's tile(setq frame-title-format'("%S" (buffer-file-name "%f"(dired-directory dired-directory "%b"))));; hide scroll-bar(scroll-bar-mode nil)(setq scroll-preserve-screen-position t)(when window-system  (global-hl-line-mode t)  (set-face-background 'hl-line "#CAFF70"));; 成对显示括号,但不来回弹跳(show-paren-mode t)(setq show-paren-style 'parentheses);; tab width(standard-display-ascii ?\t "#---")(setq default-tab-width 4)(setq-default indent-tabs-mode nil)(defun my-c-mode-hook ()(c-set-style "stroustrup")(c-set-offset 'innamespace 0))(add-hook 'c-mode-hook 'my-c-mode-hook)(add-hook 'c++-mode-hook 'my-c-mode-hook);; ibuffer(require 'ibuffer)(global-set-key "\C-x\C-b" 'ibuffer);; yes /no -> y/n(fset 'yes-or-no-p 'y-or-n-p);; close autosave(setq backup-inhibited t);; stop creating those #autosave# files(setq auto-save-default nil);; ido(require 'ido)(ido-mode t);; 字体设置,使用等宽字体(dolist (charset '(kana han symbol cjk-misc bopomofo))  (set-fontset-font (frame-parameter nil 'font)                    charset                    (font-spec :family "STHeiti" :size 12)))(set-default-font "Bitstream Vera Sans Mono 12");;======================================================;; 自定义功能或函数;;======================================================;; 换行格式转化 dos to unix(defun dos2unix ()  "Automate M-% C-q C-m RET RET"  (interactive)  (save-excursion    (goto-char (point-min))    (while (search-forward (string ?\C-m)  nil t)      (replace-match "" nil t))));; using pgup,pgDn scroll(defun window-half-height ()(max 1 (/ (1- (window-height (selected-window))) 2)))(defun scroll-up-half ()(interactive)(scroll-up (window-half-height)))(defun scroll-down-half ()(interactive)(scroll-down (window-half-height)))(global-set-key [next] 'scroll-up-half)(global-set-key [prior] 'scroll-down-half);; occur(defun isearch-occur ()"*Invoke `occur' from within isearch."(interactive)(let ((case-fold-search isearch-case-fold-search))(occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))(define-key isearch-mode-map (kbd "C-o") 'isearch-occur)

插件安装

使用包管理器安装插件,推荐如下插件

* ace-jump-mode : 方便光标跳转的插件
* smex: 一个”M-x”快捷键的增强工具,它能够使得在Emacs中调用各种命令更为方便,能更智能地对命令进行补全,还能根据使用者调用命令的频率来猜测用户可能会执行的命令
* ag : the silver searcher搜索的前端

插件安装步骤

1.列出插件

使用package-list-pacgages函数显示列插件列表

M-X : package-list-packages

2.选择插件

这里写图片描述
3.安装插件
这里写图片描述

插件配置

在.emacs文件中添加如下配置

;;======================================================;; plugin settings , 插件配置;;======================================================;;==================;; smex是一个"M-x"快捷键的增强工具,它能够使得在Emacs中调用各种命令更为方便,能更智能地对命令进行补全,还能根据使用者调用命令的频率来猜测用户可能会执行的命令;;==================(smex-initialize)(global-set-key (kbd "M-x") 'smex);;==================;; ace-jump, 方便光标跳转的插件;;=================(define-key global-map (kbd "C-c SPC") 'ace-jump-mode)(setq ace-jump-mode-scope 'window);;==================;; ag , the silver searcher搜索的前端;;==================(setq ag-highlight-search t);; (setq ag-reuse-buffers t);; Its value is ("--smart-case" "--nogroup" "--column" "--")(setq ag-arguments (list "--ignore" "TAGS" "--smart-case" "--nogroup" "--column" "--"))(global-set-key (kbd "C-c f") 'ag-project-at-point)
你可能感兴趣的文章
cppcheck c++静态代码检查
查看>>
CLOSE_WAIT和TIME_WAIT
查看>>
在C++中使用Lua
查看>>
在Dll中调用自身的位图资源
查看>>
IP校验和详解
查看>>
C++中使用Mongo执行count和distinct运算
查看>>
一些socket的编程经验
查看>>
socket编程中select的使用
查看>>
C++获取文件大小常用技巧分享
查看>>
未来5年大机遇:做贩卖多巴胺的超级玩家
查看>>
关于AIS编码解码的两个小问题
查看>>
GitHub 万星推荐:黑客成长技术清单
查看>>
可以在线C++编译的工具站点
查看>>
关于无人驾驶的过去、现在以及未来,看这篇文章就够了!
查看>>
所谓的进步和提升,就是完成认知升级
查看>>
昨夜今晨最大八卦终于坐实——人类首次直接探测到了引力波
查看>>
如何优雅、机智地和新公司谈薪水?
查看>>
为什么读了很多书,却学不到什么东西?
查看>>
长文干货:如何轻松应对工作中最棘手的13种场景?
查看>>
如何确保自己的Mac数据安全呢?这里有四个“小秘诀”
查看>>