1
0
Fork 0
website/gemini/emacs-as-an-os.gmi

177 lines
8.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

~~~~~~~~
title: Emacs as an operating system date: 2016-04-14
## modified: 2016-05-29
Emacs is sometimes jokingly called a good operating system with a bad text editor. Over the last year, I found myself using more and more of Emacs, so I decided to try out how much of an operating system it is. Of course, operating system here is referring to the programs that the user interacts with, although I would love to try out some sort of Emacs-based kernel.
```<!--more-->
```
# Emacs as a terminal emulator / multiplexer
Terminals are all about text, and Emacs is all about text as well. Not only that, but Emacs is also very good at running other processes and interacting with them. It is no surprise, I think, that Emacs works well as a terminal emulator.
Emacs comes out of the box with shell and term. Both of these commands run the shell of your choice, and give you a buffer to interact with it. Shell gives you a more emacs-y experience, while term overrides all default keymaps to give you a full terminal experience.
=> /img/emacs-terminal.png Emacs as a terminal emulator
To use emacs as a full terminal, you can bind these to a key in your window manager. Im using i3, and my keybinding looks like this:
```bindsym $mod+Shift+Return exec --no-startup-id emacs --eval "(shell)"
```
You can also create a desktop file to have a symbol to run this on a desktop environment. Try putting the following text in a file at ~/.local/share/applications/emacs-terminal.desktop:
```[Desktop Entry]
Name=Emacs Terminal
GenericName=Terminal Emulator
Comment=Emacs as a terminal emulator.
Exec=emacs --eval '(shell)'
Icon=emacs
Type=Application
Terminal=false
StartupWMClass=Emacs
```
If you want to use term instead, replace (shell) above with (term "/usr/bin/bash").
A very useful feature of terminal multiplexers is the ability to leave the shell running, even after the terminal is closed, or the ssh connection has dropped if you are connection over that. Emacs can also achieve this with its server-client mode. To use that, start emacs with emacs --daemon, and then create a terminal by running emacsclient -c --eval '(shell)'. Even after you close emacsclient, since Emacs itself is still running, you can run the same command again to get back to your shell.
One caveat is that if there is a terminal/shell already running, Emacs will automatically open that whenever you try opening a new one. This can be a problem if you are using Emacs in server-client mode, or want to have multiple terminals in the same window. In that case, you can either do M-x rename-uniquely to change the name of the existing terminal, which will make Emacs create a new one next time, or you can add that to hook in your init.el to always have that behaviour:
```(add-hook 'shell-mode-hook 'rename-uniquely)
(add-hook 'term-mode-hook 'rename-uniquely)
```
# Emacs as a shell
Of course, it is not enough that Emacs works as a terminal emulator. Why not use Emacs as a shell directly, instead of bash/zsh? Emacs has you covered for that too. You can use eshell, which is a shell implementation, completely written in Emacs Lisp. All you need to do is press M-x eshell.
=> /img/eshell.png Eshell, Emacs shell
The upside is that eshell can evaluate and expand lisp expressions, as well as redirecting the output to Emacs buffers. The downside is however, eshell is not feature complete. It lacks some features such as input redirection, and the documentation notes that it is inefficient at piping output between programs.
If you want to use eshell instead of shell or term, you can replace shell in the examples of terminal emulator section with eshell.
# Emacs as a mail cilent
Zawinskis Law[a]: Every program attempts to expand until it can read mail. Of course, it would be disappointing for Emacs to not handle mail as well.
=> http://www.catb.org/~esr/jargon/html/Z/Zawinskis-Law.html [a]
Emacs already ships with some mail capability. To get a full experience however, Id recommend using mu4e[a] (mu for emacs). I have personally set up OfflineIMAP[b] to retrieve my emails, and mu4e gives me a nice interface on top of that.
=> http://www.djcbsoftware.nl/code/mu/mu4e.html [a]
=> http://www.offlineimap.org/ [b]
=> /img/mu4e.png mu4e, mail client
Im not going to talk about the configurations of these programs, Id recommend checking out their documentations. Before ending this section, I also want to mention mu4e-alert[a] though.
=> https://github.com/iqbalansari/mu4e-alert [a]
# Emacs as a feed reader (RSS/Atom)
Emacs handles feeds very well too. The packages Im using here are Elfeed[a] and Elfeed goodies[b]. Emacs can even show images in the feeds, so it covers everything I need from a feed reader.
=> https://github.com/skeeto/elfeed [a]
=> https://github.com/algernon/elfeed-goodies [b]
=> /img/elfeed.png Elfeed, feed reader
# Emacs as a file manager
Why use a different program to manage your files when you can use Emacs? Emacs ships with dired, as well as image-dired. This gives you a file browser, with optional image thumbnail support.
# Emacs as a document viewer
Want to read a pdf? Need a program to do a presentation? Again, Emacs.
=> /img/docview.png Docview, document viewer
Emacs comes with DocView[a] which has support for PDF, OpenDocument and Microsoft Office files. It works surprisingly well.
=> https://www.gnu.org/software/emacs/manual/html_node/emacs/Document-View.html [a]
Also, PDF Tools[a] brings even more PDF viewing capabilities to Emacs, including annotations, text search and outline. After installing PDF Tools, Emacs has become my primary choice for reading PDF files.
=> https://github.com/politza/pdf-tools [a]
# Emacs as a browser
Emacs comes out of box with eww[a], a text-based web browser with support for images as well.
=> https://www.gnu.org/software/emacs/manual/html_node/eww/index.html#Top [a]
=> /img/eww.png eww, browser
Honestly, I dont think Ill be using Emacs to browse the web. But still, it is nice that the functionality is there.
# Emacs as a music player
Emacs can also act as a music player thanks to EMMS[a], Emacs MultiMedia System. If you are wondering, it doesnt play the music by itself but instead uses other players like vlc or mpd.
=> https://www.gnu.org/software/emms/ [a]
It has support for playlists, and can show thumbnails as well. For the music types, it supports whatever the players it uses support, which means that you can basically use file type.
# Emacs as a IRC client
I dont use IRC a lot, but Emacs comes out of the box with support for that as well thanks to ERC[a].
=> https://www.emacswiki.org/emacs?action=browse;oldid=EmacsIrcClient;id=ERC [a]
=> /img/erc.png erc, Emacs IRC client
# Emacs as a text editor
Finally, Emacs also can work well as a text editor.
Emacs is a pretty fine text editor out of the box, but I want to mention some packages here.
First, multiple cursors[a]. Multiple cursors mode allows you to edit text at multiple places at the same time.
=> https://github.com/magnars/multiple-cursors.el [a]
I also want to mention undo-tree[a]. It acts like a mini revision control system, allowing you to undo and redo without ever losing any text.
=> http://www.dr-qubit.org/emacs.php#undo-tree [a]
Another great mode is iy-go-to-char[a]. It allows you to quickly jump around by going to next/previous occurrances of a character. It is very useful when you are trying to move around a line.
=> https://github.com/doitian/iy-go-to-char [a]
Ace Jump Mode[a] allows you to jump around the visible buffers. It can jump around based on initial characters of words, or jump to specific lines. It can also jump from one buffer to another, which is very useful when you have several buffers open in your screen.
=> https://github.com/winterTTr/ace-jump-mode/ [a]
=> /img/ace-jump-mode.png Ace Jump Mode
Finally, I want to mention ag.el[a], which is an Emacs frontend for the silver searcher. If you dont know about ag, it is a replacement for grep that recursively searches directories, and has some special handling for projects, and is very fast.
=> https://github.com/Wilfred/ag.el [a]
# Emacs as an IDE
People sometimes compare Emacs to IDEs and complain that a text editor such as Emacs doesnt have enough features. What they are forgetting, of course, is that Emacs is an operating system, and we can have an IDE in it as well.
There are different packages for every language, so Ill be only speaking on language agnostic ones.
For interacting with git, magit[a] is a wonderful interface.
=> http://magit.vc/ [a]
=> /img/magit.png Magit, Git Porcelain
For auto-completion, Company mode[a] works wonders. I rely heavily on completion while writing code, and company mode has support for anything I tried writing.
=> https://company-mode.github.io/ [a]
If you like having your code checked as you type, flycheck[a] has you covered. It has support for many tools and languages.
=> https://www.flycheck.org/ [a]
=> /img/company-flycheck.png Company Mode and Flycheck