translate done: 20200128 Send email and check your calendar with Emacs.md

This commit is contained in:
darksun 2020-02-24 21:52:56 +08:00
parent 0327572103
commit 44d5757277
3 changed files with 200 additions and 159 deletions

View File

@ -8,84 +8,123 @@
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
6 things you should be doing with Emacs
你应该用Emacs做的6件事
======
Here are six things you may not have realized you could do with Emacs.
下面是您可能没有意识到的Emacs可以做的六件事。
Then, get our new cheat sheet to get the most out of Emacs.
然后使用我们的新备忘单来充分利用Emacs。
![Text editor on a browser, in blue][1]
[在蓝色浏览器上给编辑发短信][1]
Imagine using Python's IDLE interface to edit text. You would be able to load files into memory, edit them, and save changes. But every action you perform would be defined by a Python function. Making a word all capitals, for instance, calls **upper()**, opening a file calls **open**, and so on. Everything in your text document is a Python object and can be manipulated accordingly. From the user's perspective, it's the same experience as any text editor. For a Python developer, it's a rich Python environment that can be changed and developed with just a few custom functions in a config file.
想象一下使用Python的空闲接口来编辑文本。您可以将文件加载到内存中编辑它们并保存更改。但是您执行的每个操作都将由Python函数定义。例如使一个单词全部大写调用**upper()**,打开一个文件调用**open**等等。文本文档中的所有内容都是Python对象可以相应地进行操作。从用户的角度来看这与任何文本编辑器的体验都是一样的。对于Python开发人员来说这是一个丰富的Python环境只需在配置文件中添加几个自定义函数就可以对其进行更改和开发。
This is what [Emacs][2] does for the 1958 programming language [Lisp][3]. In Emacs, there's no separation between the Lisp engine running the application and the arbitrary text you type into it. To Emacs, everything is Lisp data, so everything can be analyzed and manipulated programmatically.
这就是[Emacs][2]对1958年的编程语言[Lisp][3]所做的。在Emacs中运行应用程序的Lisp引擎与您输入的任意文本之间没有分离。对于Emacs一切都是Lisp数据因此一切都可以通过编程进行分析和操作。
That makes for a powerful user interface (UI). But if you're a casual Emacs user, you may only be scratching the surface of what it can do for you. Here are six things you may not have realized you could do with Emacs.
这就形成了一个强大的用户界面(UI)。但是如果您是Emacs的普通用户您可能只了解它能为您做些什么。下面是您可能没有意识到的Emacs可以做的六件事。
## Use Tramp mode for cloud editing
使用流浪汉模式进行克劳德编辑
Emacs has been network-transparent for a lot longer than has been trendy, and today it still provides one of the smoothest remote editor experiences available. The [Tramp mode][4] in Emacs (formerly known as RPC mode) stands for "Transparent Remote (file) Access, Multiple Protocol," which spells out exactly what it offers: easy access to remote files you want to edit over most popular network protocols. The most popular and safest protocol for remote editing these days is [OpenSSH][5], so that's the default.
Emacs实现网络透明的时间要比流行的时间长得多而且时至今日它仍然提供最流畅的远程编辑体验。Emacs中的[Tramp模式][4](以前称为RPC模式)代表“透明的远程(文件)访问,多协议”,它详细说明了它提供的功能:通过最流行的网络协议轻松访问您希望编辑的远程文件。目前最流行、最安全的远程编辑协议是[OpenSSH][5],因此它是默认的。
Tramp is already included in Emacs 22.1 or greater, so to use Tramp, you just open a file in the Tramp syntax. In the **File** menu of Emacs, select **Open File**. When prompted in the mini-buffer at the bottom of the Emacs window, enter the file name using this syntax:
在Emacs 22.1或更高版本中已经包含了Tramp因此要使用Tramp只需在Tramp语法中打开一个文件。在Emacs的**File**菜单中,选择**Open File**。当在Emacs窗口底部的小缓冲区中出现提示时使用以下语法输入文件名:
```
引用----------------------------------------------------
`/ssh:user@example.com:/path/to/file`
```
If you are required to log in interactively, Tramp prompts you for your password. However, Tramp uses OpenSSH directly, so to avoid interactive prompts, you can also add your hostname, username, and SSH key path to your **~/.ssh/config** file. Like Git, Emacs uses your SSH config first and only stops to ask for more information in the event of an error.
如果需要交互式登录Tramp会提示您输入密码。但是Tramp直接使用OpenSSH所以为了避免交互提示您还可以将您的主机名、用户名和SSH密钥路径添加到您的**~/。ssh / config文件* *。与Git一样Emacs首先使用SSH配置只有在出现错误时才会停下来询问更多信息。
Tramp is great for editing files that don't exist on your computer, and the user experience is not noticeably any different from editing a local file. The next time you start to SSH into a server just to launch a Vim or Emacs session, try Tramp instead.
Tramp非常适合编辑计算机上不存在的文件用户体验与编辑本地文件没有明显的区别。下一次当您为了启动Vim或Emacs会话而开始SSH到服务器时请尝试使用Tramp。
## Calendaring
# Calendaring
If you parse text better than you parse graphical interfaces, you'll be happy to know that you can schedule your day (or life) in plain text with Emacs but still get fancy notifications on your mobile device with open source [Org mode][6] viewers.
如果您解析文本比解析图形界面更好那么您会很高兴地知道您可以使用Emacs以纯文本方式安排您的一天(或生活),但仍然可以在您的移动设备上使用开放源码[Org模式][6]查看器获得花哨的通知。
The process takes a little setup to create a convenient way to sync your agenda with your mobile device (I use Git, but you could invoke Bluetooth, KDE Connect, Nextcloud, or your file synchronization tool of choice), and you have to install an Org mode viewer (such as [Orgzly][7]) and a Git client app on your mobile. Once you've got your infrastructure sorted, though, the process is inherently perfectly integrated with your usual (or developing, if you're a new user) Emacs workflow. You can refer to your agenda easily in Emacs, make updates to your schedule, and generally stay on task. Pushing changes to your agenda is reflected on your mobile, so you can stay organized even when Emacs isn't available.
这个过程需要一些设置创建一个方便的方式来移动设备同步你的议程(我使用Git,但你可以调用蓝牙,KDE连接,Nextcloud,或您的文件同步工具的选择),你必须安装一个组织模式查看器(如[Orgzly][7])和一个Git客户对你的移动应用程序。但是一旦您对基础设施进行了排序该流程就会与您通常使用的Emacs工作流完美地集成在一起(如果您是新用户,则会进行开发)。您可以在Emacs中方便地查阅您的日程更新您的日程并通常停留在任务上。推动您的议程的变化反映在您的移动设备上因此即使Emacs不可用您也可以保持组织性。
![][8]
Intrigued? Read my step-by-step guide about [calendaring with Org mode and Git][9].
感兴趣吗?阅读我的关于[使用Org模式和Git进行日历][9]的逐步指南。
## Access the terminal
访问终端
There are [lots of terminal emulators][10] available. Although the Elisp terminal emulator in Emacs isn't the greatest general-purpose one, it's got two notable advantages.
有[许多终端模拟器][10]可用。尽管Emacs中的Elisp终端仿真器不是最强大的通用仿真器但是它有两个显著的优点。
1. **Opens in an Emacs buffer: **I use Emacs' Elisp shell because it's conveniently located in my Emacs window, which I often run in fullscreen. It's a small but significant advantage to have a terminal just a **Ctrl+x+o** (or C-x o in Emacs notation) away, and it's especially nice to be able to glance over at it for status reports when it's running a lengthy job.
2. **Easy copying and pasting if no system clipboard is available:** Whether I'm too lazy to move my hand from the keys to the mouse, or I don't have mouse functionality because I'm running Emacs in a remote console, having a terminal in Emacs can sometimes mean a quick transfer of data from my Emacs buffer to Bash.
1. **Opens in an Emacs buffer: **I use Emacs' Elisp shell because it's conveniently located in my Emacs window, which I often run in fullscreen. It's a small but significant advantage to have a terminal just a **Ctrl+x+o** (or C-x o in Emacs notation) away, and it's especially nice to be able to glance over at it for status reports when it's running a lengthy job.
1. 我使用Emacs的Elisp shell因为它方便地位于我的Emacs窗口我经常在全屏运行。这是一个小但重要的优势有一个终端只是**Ctrl+x+o**(或C-x o在Emacs符号),它是特别好的,能够浏览它的状态报告,当它运行一个漫长的作业。
2. **Easy copying and pasting if no system clipboard is available:** Whether I'm too lazy to move my hand from the keys to the mouse, or I don't have mouse functionality because I'm running Emacs in a remote console, having a terminal in Emacs can sometimes mean a quick transfer of data from my Emacs buffer to Bash.
2. * *简单的复制和粘贴,如果没有可用系统剪贴板:* *是否我太懒惰的关键将我的手从鼠标,或者我没有鼠标功能,因为我在远程控制台运行Emacs,在Emacs有时意味着终端快速传输数据从我的Emacs缓冲Bash。
To try the Emacs terminal, type **Alt**+**x** (**M-x** in Emacs notation), then type **shell**, and press **Return**.
要尝试Emacs终端输入**Alt**+**x** (Emacs符号中的**M-x**),然后输入**shell**,然后按**Return**。
## Use Racket mode
使用球拍模式
[Racket][11] is an exciting emerging Lisp dialect with a dynamic programming environment, a GUI toolkit, and a passionate community. The default editor when learning Racket is DrRacket, which has a Definitions panel at the top and an Interactions panel at the bottom. Using this setup, the user writes definitions that affect the Racket runtime. Imagine the old [Logo Turtle][12] program, but with a terminal instead of just a turtle.
[11]是一种激动人心的新兴Lisp语言拥有动态编程环境、GUI工具包和热情的社区。学习球拍的默认编辑器是dr球拍它的顶部有一个定义面板底部有一个交互面板。使用此设置用户可以编写影响球拍运行时的定义。想象一下旧的[Logo Turtle][12]程序但是有一个终端而不是一个Turtle。
![Racket-mode][13]
[Racket-mode] [13] !
LGPL sample code by PLT
由PLT提供的LGPL示例代码
Emacs, being based on Lisp, makes a great integrated development environment (IDE) for advanced Racket coders. It doesn't ship with [Racket mode][14] (yet), but you can install Racket mode and several other helper extensions using the Emacs package installer. To install it, press **Alt**+**X** (**M-x** in Emacs notation), type **package-install**, and press **Return**. Then enter the package you want to install (**racket-mode**), and press **Return**.
基于Lisp的Emacs为高级球拍编程人员提供了一个很好的集成开发环境(IDE)。它还没有[球拍模式][14]但你可以安装球拍模式和其他几个助手扩展使用Emacs包安装程序。要安装它按**Alt**+**X** (**M-x** Emacs符号),键入**package-install**,然后按**Return**。然后输入要安装的包(**rac模式**),按**Return**。
Enter Racket mode with **M-x racket-mode**. If you're new to Racket but not to Lisp or Emacs, start with the excellent [Quick introduction to Racket with pictures][15].
进入球拍模式,使用**M-x球拍模式**。如果你是球拍新手但不是口齿不清或Emacs开始优秀[快速介绍球拍与图片][15]。
## Scripting
# # Scripting
You might know that Bash scripts are popular for automating and enhancing your Linux or Unix experience. You may have heard that Python does a pretty good job of that, too. But did you know that Lisp scripts can be run in much the same way? There's sometimes confusion about just how useful Lisp really is because many people are introduced to Lisp through Emacs, so there's the latent impression that the only way to run Lisp in the 21st century is to open an Emacs window. Luckily, that's not the case at all, and Emacs is a great IDE for the tools that enable you to run Lisp scripts as general system executables.
您可能知道Bash脚本在自动化和增强您的Linux或Unix体验方面很流行。您可能听说过Python在这方面也做得很好。但是你知道Lisp脚本可以用同样的方式运行吗?有时人们会对Lisp到底有多有用感到困惑因为许多人是通过Emacs来了解Lisp的因此有一种潜在的印象即在21世纪运行Lisp的惟一方法是打开Emacs窗口。幸运的是事实并非如此Emacs是一个很好的IDE它支持将Lisp脚本作为一般的系统可执行文件来运行。
There are two popular modern Lisps, aside from Elisp, that are easy to run as standalone scripts.
除了Elisp之外有两种流行的现代lisp很容易作为独立脚本运行。
1. **Racket:** You can run Racket scripts relying on your system's Racket install to provide runtime support, or you can use **raco exe** to produce an executable. The **raco exe** command packages your code together with runtime support files to create an executable. The **raco distribute** command then packages that executable into a distribution that works on other machines. Emacs has many Racket-specific tools, so creating Racket files in Emacs is easy and efficient.
1. **Racket:** You can run Racket scripts relying on your system's Racket install to provide runtime support, or you can use **raco exe** to produce an executable. The **raco exe** command packages your code together with runtime support files to create an executable. The **raco distribute** command then packages that executable into a distribution that works on other machines. Emacs has many Racket-specific tools, so creating Racket files in Emacs is easy and efficient.
1. **球拍:**你可以运行球拍脚本依赖于你的系统的球拍安装提供运行时支持,或者你可以使用**raco exe**产生一个可执行文件。**raco exe**命令将代码和运行时支持文件打包,以创建可执行文件。然后,**raco distribution **命令将可执行文件打包到在其他机器上工作的发行版中。Emacs有许多特定于球拍的工具因此在Emacs中创建球拍文件既简单又有效。
2. **GNU Guile:** [GNU Guile][16] (short for "GNU Ubiquitous Intelligent Language for Extensions") is an implementation of the [Scheme][17] programming language that's used for creating applications and games for the desktop, internet, terminal, and more. Writing Scheme is easy, using any one of the many Scheme extensions in Emacs. For example, here's a "Hello world" script in Guile: [code] #!/usr/bin/guile -s
2. **GNU Guile:** [GNU Guile][16] (short for "GNU Ubiquitous Intelligent Language for Extensions") is an implementation of the [Scheme][17] programming language that's used for creating applications and games for the desktop, internet, terminal, and more. Writing Scheme is easy, using any one of the many Scheme extensions in Emacs. For example, here's a "Hello world" script in Guile: [code] #!/usr/bin/guile -s
2. **GNU Guile:** [GNU Guile][16](“GNU通用智能语言扩展”的缩写)是[Scheme][17]编程语言的一个实现它用于为桌面、internet、终端等创建应用程序和游戏。使用Emacs中众多Scheme扩展中的任何一个编写Scheme都很容易。例如这里有一个用Guile编写的“Hello world”脚本:[code] #!/usr/bin/guile - s
!#
(display "hello world")
(显示“hello world”)
     (newline) [/code] Compile and run it with the **guile** command: [code] $ guile ./hello.scheme
(换行)[/code]编译并运行**guile**命令:[code] $ guile ./hello.scheme
;;; compiling /home/seth/./hello.scheme
;;;compiling / home /塞斯-你好。怀廷
;;; compiled [...]/hello.scheme.go
;;;[…]/ hello.scheme.go编译
hello world
你好,世界
$ guile ./hello.scheme
hello world
你好scheme
hello world
你好,世界
```
引用----------------------------------------------------
## Run Elisp without Emacs
Emacs can serve as an Elisp runtime, but you don't have to "open" Emacs in the traditional sense. The **\--script** option allows you to run Elisp scripts using Emacs as the engine but without launching the Emacs GUI (not even its terminal-based one). In this example, the **-Q** option causes Emacs to ignore your **.emacs** file to avoid any delays in executing the Elisp script (if your script relies upon something

View File

@ -1,152 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (lujun9972)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Send email and check your calendar with Emacs)
[#]: via: (https://opensource.com/article/20/1/emacs-mail-calendar)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
Send email and check your calendar with Emacs
======
Manage your email and view your schedule with the Emacs text editor in
the eighteenth in our series on 20 ways to be more productive with open
source in 2020.
![Document sending][1]
Last year, I brought you 19 days of new (to you) productivity tools for 2019. This year, I'm taking a different approach: building an environment that will allow you to be more productive in the new year, using tools you may or may not already be using.
### Doing (almost) all the things with Emacs, part 1
Two days ago, I shared that I use both [Vim][2] and [Emacs][3] regularly, and on days [16][4] and [17][5] of this series, I explained how to do almost everything in Vim. Now, it's time for Emacs!
![Mail and calendar in Emacs][6]
Before I get too far, I should explain two things. First, I'm doing everything here using the default Emacs configuration, not [Spacemacs][7], which I have [written about][8]. Why? Because I will be using the default keyboard mappings so that you can refer back to the documentation and not have to translate things from "native Emacs" to Spacemacs. Second, I'm not setting up Org mode in this series. Org mode almost needs an entire series on its own, and, while it is very powerful, the setup can be quite complex.
#### Configure Emacs
Configuring Emacs is a little bit more complicated than configuring Vim, but in my opinion, it is worth it in the long run. Start by creating a configuration file and opening it in Emacs:
```
mkdir ~/.emacs.d
emacs ~/.emacs.d/init.el
```
Next, add some additional package sources to the built-in package manager. Add the following to **init.el**:
```
(package-initialize)
(add-to-list 'package-archives '("melpa" . "<http://melpa.org/packages/>"))
(add-to-list 'package-archives '("org" . "<http://orgmode.org/elpa/>") t)
(add-to-list 'package-archives '("gnu" . "<https://elpa.gnu.org/packages/>"))
(package-refresh-contents)
```
Save the file with **Ctrl**+**x** **Ctrl**+**s**, exit with **Ctrl**+**x** **Ctrl**+**c**, and restart Emacs. It will download all the package lists at startup, and then you should be ready to install things with the built-in package manager. Start by typing **Meta**+**x** to bring up a command prompt (the **Meta** key is the **Alt** key on most keyboards or **Option** on MacOS). At the command prompt, type **package-list-packages** to bring up a list of packages you can install. Go through the list and select the following packages with the **i** key:
```
bbdb
bbdb-vcard
calfw
calfw-ical
notmuch
```
Once the packages are selected, press **x** to install them. Depending on your internet connection, this could take a while. You may see some compile errors, but it's safe to ignore them. Once it completes, open **~/.emacs.d/init.el** with the key combination **Ctrl**+**x** **Ctrl**+**f**, and add the following lines to the file after **(package-refresh-packages)** and before **(custom-set-variables**. Emacs uses the **(custom-set-variables** line internally, and you should never, ever modify anything below it. Lines beginning with **;;** are comments.
```
;; Set up bbdb
(require 'bbdb)
(bbdb-initialize 'message)
(bbdb-insinuate-message)
(add-hook 'message-setup-hook 'bbdb-insinuate-mail)
;; set up calendar
(require 'calfw)
(require 'calfw-ical)
;; Set this to the URL of your calendar. Google users will use
;; the Secret Address in iCalendar Format from the calendar settings
(cfw:open-ical-calendar "<https://path/to/my/ics/file.ics>")
;; Set up notmuch
(require 'notmuch)
;; set up mail sending using sendmail
(setq send-mail-function (quote sendmail-send-it))
(setq user-mail-address "[myemail@mydomain.com][9]"
      user-full-name "My Name")
```
Now you are ready to start Emacs with your setup! Save the **init.el** file (**Ctrl**+**x** **Ctrl**+**s**), exit Emacs (**Ctrl**+**x** **Ctrl**+**c**), and then restart it. It will take a little longer to start this time.
#### Read and write email in Emacs with Notmuch
Once you are at the Emacs splash screen, you can start reading your email with [Notmuch][10]. Type **Meta**+**x notmuch**, and you'll get Notmuch's Emacs interface.
![Reading mail with Notmuch][11]
All the items in bold type are links to email views. You can access them with either a mouse click or by tabbing between them and pressing **Return** or **Enter**. You can use the search bar to
search Notmuch's database using the [same syntax][12] as you use on Notmuch's command line. If you want, you can save any searches for later use with the **[save]** button, and they will be added to the list at the top of the screen. If you follow one of the links, you will get a list of the relevant email messages. You can navigate the list with the **Arrow** keys, and press **Enter** on the message you want to read. Pressing **r** will reply to a message, **f** will forward the message, and **q** will exit the current screen.
You can write a new message by typing **Meta**+**x compose-mail**. Composing, replying, and forwarding all bring up the mail writing interface. When you are done writing your email, press **Ctrl**+**c Ctrl**+**c** to send it. If you decide you don't want to send it, press **Ctrl**+**c Ctrl**+**k** to kill the message compose buffer (window).
#### Autocomplete email addresses in Emacs with BBDB
![Composing a message with BBDB addressing][13]
But what about your address book? That's where [BBDB][14] comes in. But first, import all your addresses from [abook][15] by opening a command line and running the following export command:
```
`abook --convert --outformat vcard --outfile ~/all-my-addresses.vcf --infile ~/.abook/addresses`
```
Once Emacs starts, run **Meta**+**x bbdb-vcard-import-file**. It will prompt you for the file name you want to import, which is **~/all-my-addresses.vcf**. After the import finishes, when you compose a message, you can start typing a name and use **Tab** to search and autocomplete the "To" field. BBDB will also open a buffer for the contact so you can make sure it's the correct one.
Why do it this way when you already have each address as a **vcf.** file from [vdirsyncer][16]? If you are like me, you have a LOT of addresses, and doing them one at a time is a lot of work. This way, you can take everything you have in abook and make one big file.
#### View your calendar in Emacs with calfw
![calfw calendar][17]
Finally, you can use Emacs to look at your calendar. In the configuration section above, you installed the [calfw][18] package and added lines to tell it where to find the calendars to load. Calfw is short for the Calendar Framework for Emacs, and it supports many calendar formats. Since I use Google calendar, that is the link I put into my config. Your calendar will auto-load at startup, and you can view it by switching the **cfw-calendar** buffer with the **Ctrl**+**x**+**b** command.
Calfw offers views by the day, week, two weeks, and month. You can select the view from the top of the calendar and navigate your calendar with the **Arrow** keys. Unfortunately, calfw can only view calendars, so you'll still need to use something like [khal][19] or a web interface to add, delete, and modify events.
So there you have it: mail, calendars, and addresses in Emacs. Tomorrow I'll do even more.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/emacs-mail-calendar
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[lujun9972](https://github.com/lujun9972)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/email_paper_envelope_document.png?itok=uPj_kouJ (Document sending)
[2]: https://www.vim.org/
[3]: https://www.gnu.org/software/emacs/
[4]: https://opensource.com/article/20/1/vim-email-calendar
[5]: https://opensource.com/article/20/1/vim-task-list-reddit-twitter
[6]: https://opensource.com/sites/default/files/uploads/productivity_18-1.png (Mail and calendar in Emacs)
[7]: https://www.spacemacs.org/
[8]: https://opensource.com/article/19/12/spacemacs
[9]: mailto:myemail@mydomain.com
[10]: https://notmuchmail.org/
[11]: https://opensource.com/sites/default/files/uploads/productivity_18-2.png (Reading mail with Notmuch)
[12]: https://opensource.com/article/20/1/organize-email-notmuch
[13]: https://opensource.com/sites/default/files/uploads/productivity_18-3.png (Composing a message with BBDB addressing)
[14]: https://www.jwz.org/bbdb/
[15]: https://opensource.com/article/20/1/sync-contacts-locally
[16]: https://opensource.com/article/20/1/open-source-calendar
[17]: https://opensource.com/sites/default/files/uploads/productivity_18-4.png (calfw calendar)
[18]: https://github.com/kiwanami/emacs-calfw
[19]: https://khal.readthedocs.io/en/v0.9.2/index.html

View File

@ -0,0 +1,154 @@
[#]: collector: (lujun9972)
[#]: translator: (lujun9972)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Send email and check your calendar with Emacs)
[#]: via: (https://opensource.com/article/20/1/emacs-mail-calendar)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
使用 Emacs 发送电子邮件和检查日历
======
使用 Emacs 文本编辑器管理电子邮件和查看日程安排,这是本系列文章 (2020 年使用开放源码提高生产力的 20 种方法)的第十八篇,。
![Document sending][1]
去年,我给你们带来了 2019 年的 19 天新生产力工具系列。今年,我将采取一种不同的方式:建立一个新的环境,让你使用已用或未用的工具来在新的一年里变得更有效率。
### 使用 Emacs 做(几乎)所有的事情,第 1 部分
两天前,我曾经说过我经常使用 [Vim][2] 和 [Emacs][3],在本系列的 [16][4] 和 [17][5] 天,我讲解了如何在 Vim 中做几乎所有的事情。现在Emacs 的时间到了!
[Emacs 中的邮件和日历 ][6]
在深入之前,我需要说明两件事。首先,我这里使用默认的 Emacs 配置,而不是我之前[写过 ][8] 的 [Spacemacs][7]。为什么呢?因为这样一来我使用的就是默认快捷键,从而使你可以参考文档,而不必将“本机 Emacs” 转换为 Spacemacs。第二在本系列文章中我没有对 Org 模式进行任何设置。Org 模式本身几乎可以自成一个完整的系列,它非常强大,但是设置可能非常复杂。
#### 配置 Emacs
配置 Emacs 比配置 Vim 稍微复杂一些,但以我之见,从长远来看,这样做是值得的。首先我们创建一个配置文件,并在 Emacs 中打开它:
```
mkdir ~/.emacs.d
emacs ~/.emacs.d/init.el
```
Nextadd some additional package sources to the built-in package manager。Add the following to **init.el**:
接下来,向内置的包管理器添加一些额外的包源。在 **init.el** 中添加以下内容:
```
(package-initialize)
(add-to-list 'package-archives '("melpa" . "<http://melpa.org/packages/>"))
(add-to-list 'package-archives '("org" . "<http://orgmode.org/elpa/>") t)
(add-to-list 'package-archives '("gnu" . "<https://elpa.gnu.org/packages/>"))
(package-refresh-contents)
```
使用 `Ctrl+x Ctrl+s` 保存文件,然后按下 `Ctrl+x Ctrl+c` 退出,再重启 Emacs。Emacs 会在启动时下载所有的插件包列表,之后你就可以使用内置的包管理器安装插件了。
输入 `Meta+x` 会弹出命令提示符(大多数键盘上 **Meta** 键就是的 **Alt** 键,而在 MacOS 上则是 **Option**)。在命令提示符下输入 **package-list-packages** 就会显示可以安装的包列表。遍历该列表并使用 **i** 键选择以下包:
```
bbdb
bbdb-vcard
calfw
calfw-ical
notmuch
```
选好软件包后按 **x** 安装它们。根据你的网络连接情况,这可能需要一段时间。你也许会看到一些编译错误,但是可以忽略它们。
安装完成后,使用组合键 `Ctrl+x Ctrl+f` 打开 `~/.emacs.d/init.el`,并在 `(package-refresh-packages)` 之后 `(custom-set-variables` 之前添加以下行到文件中。
`(custom-set-variables` 行由 Emacs 内部维护,你永远不应该修改它之后的任何内容。以**;;**开头的行则是注释。
```
;; Set up bbdb
(require 'bbdb)
(bbdb-initialize 'message)
(bbdb-insinuate-message)
(add-hook 'message-setup-hook 'bbdb-insinuate-mail)
;; set up calendar
(require 'calfw)
(require 'calfw-ical)
;; Set this to the URL of your calendar. Google users will use
;; the Secret Address in iCalendar Format from the calendar settings
(cfw:open-ical-calendar "<https://path/to/my/ics/file.ics>")
;; Set up notmuch
(require 'notmuch)
;; set up mail sending using sendmail
(setq send-mail-function (quote sendmail-send-it))
(setq user-mail-address "[myemail@mydomain.com][9]"
      user-full-name "My Name")
```
现在,您已经准备好使用自己的配置启动 Emacs 了!保存 `init.el` 文件 (`Ctrl+x Ctrl+s`),退出 Emacs(`Ctrl+x Ctrl+c`),然后重启之。这次重启要多花些时间。
#### 使用 Notmuch 在 Emacs 中读写电子邮件
一旦你看到了 Emacs 启动屏幕,你就可以使用 [Notmuch][10] 来阅读电子邮件了。键入 `Meta+x notmuch`,您将看到 notmuch 的 Emacs 接口。
![使用 notmuch 阅读邮件 ][11]
所有加粗的项目都是指向电子邮件视图的链接。你可以通过点击鼠标或者使用 tab 键在它们之间跳转并按 **Return****Enter** 来访问它们。你可以使用搜索栏来搜索 Notmuch 的数据库,语法与 Notmuch 命令行上的[语法 ][12] 相同。如果你愿意,还可以使用 **[save]** 按钮保存搜索以便未来使用,这些搜索会被添加到屏幕顶部的列表中。如果你进入一个链接就会看到一个相关电子邮件的列表。您可以使用**箭头**键在列表中导航,并在要读取的消息上按 **Enter**。按 **r** 可以回复一条消息,**f** 转发该消息,**q** 退出当前屏幕。
You can write a new message by typing **Meta**+**x compose-mail**。Composingreplyingand forwarding all bring up the mail writing interface。When you are done writing your emailpress **Ctrl**+**c Ctrl**+**c** to send it。If you decide you don't want to send itpress **Ctrl**+**c Ctrl**+**k** to kill the message compose buffer (window)。
您可以通过键入 `Meta+x compose-mail` 来编写新消息。撰写、回复和转发都将打开编写邮件的接口。写完邮件后,按 `Ctrl+c Ctrl+c` 发送。如果你决定不发送它,按 `Ctrl+c Ctrl+k` 关闭消息撰写缓冲区(窗口)。
#### 使用 BBDB 在 Emacs 中自动补完电子邮件地址
[在消息中使用 BBDB 地址 ][13]
那么通讯录怎么办?这就是 [BBDB][14] 发挥作用的地方。但首先我们需要从 [abook][15] 导入所有地址,方法是打开命令行并运行以下导出命令:
```
`abook --convert --outformat vcard --outfile ~/all-my-addresses.vcf --infile ~/.abook/addresses`
```
Emacs 启动后,运行 `Meta+x bbdb-vcard-import-file`。它将提示你输入要导入的文件名,即 `~/all-my-address.vcf`。导入完成后,在编写消息时,可以开始输入名称并使用 **Tab** 搜索和自动完成 “to” 字段的内容。BBDB 还会打开一个联系人缓冲区,以便你确保它是正确的。
既然在 [vdirsyncer][16] 中已经为每个地址都生成了对应的 vcf。文件了为什么我们还要这样做呢如果你像我一样有许多地址一次处理一个地址是很麻烦的。这样做你就可以把所有的东西都放在一本书里做成一个大文件。
#### 使用 calfw 在 Emacs 中浏览日历
![calfw 日历 ][17]
最后,你可以使用 Emacs 查看日历。在上面的配置中,你安装了 [calfw][18] 包并添加了一些行来告诉它在哪里可以找到要加载的日历。Calfw 是 Emacs 日历框架的简称,它支持多种日历格式。我使用的是谷歌日历,这也是我放在配置中的链接。日历将在启动时自动加载,您可以通过 `Ctrl+x+b` 命令切换到 **cfw-calendar** 缓冲区来查看日历。
Calfw 提供日、周、双周和月视图。您可以在日历顶部选择视图,并使用**箭头**键导航日历。不幸的是calfw 只能查看日历,所以您仍然需要使用 [khal][19] 之类的工具或通过 web 界面来添加、删除和修改事件。
这就是 Emacs 中的邮件、日历和邮件地址。明天我会展示更多。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/emacs-mail-calendar
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[lujun9972](https://github.com/lujun9972)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/email_paper_envelope_document.png?itok=uPj_kouJ (Document sending)
[2]: https://www.vim.org/
[3]: https://www.gnu.org/software/emacs/
[4]: https://opensource.com/article/20/1/vim-email-calendar
[5]: https://opensource.com/article/20/1/vim-task-list-reddit-twitter
[6]: https://opensource.com/sites/default/files/uploads/productivity_18-1.png (Mail and calendar in Emacs)
[7]: https://www.spacemacs.org/
[8]: https://opensource.com/article/19/12/spacemacs
[9]: mailto:myemail@mydomain.com
[10]: https://notmuchmail.org/
[11]: https://opensource.com/sites/default/files/uploads/productivity_18-2.png (Reading mail with Notmuch)
[12]: https://opensource.com/article/20/1/organize-email-notmuch
[13]: https://opensource.com/sites/default/files/uploads/productivity_18-3.png (Composing a message with BBDB addressing)
[14]: https://www.jwz.org/bbdb/
[15]: https://opensource.com/article/20/1/sync-contacts-locally
[16]: https://opensource.com/article/20/1/open-source-calendar
[17]: https://opensource.com/sites/default/files/uploads/productivity_18-4.png (calfw calendar)
[18]: https://github.com/kiwanami/emacs-calfw
[19]: https://khal.readthedocs.io/en/v0.9.2/index.html