# X things you should be doing with Emacs by Seth Kenlon 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 is defined by a Python function. Making a word all-capitals, for instance, calls ``upper()``, opening a file calls ``open``, and so on. And everything in your text document is a Python object and can be maniplated 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. That's what Emacs is for the 1958 language, Lisp. In Emacs, there's no separation between the Lisp engine running the application and the arbitrary text you type into it. Everything is Lisp data to Emacs, and so everything can be analyzed and manipulated programmatically. That makes for a powerful UI. If you're a casual Emacs user, you may only be scratching the surface of what Emacs can do for you. Here are X things you may not have realised you could use Emacs to do. ## 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 in Emacs (formerly ``rpc`` mode) stands for *transparent remote access, multiple protocols*, 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, so that's the default. Tramp itself 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: ``` /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 host name, user name, 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 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. ## 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 viewers. The process takes a little setup; you have to set up a convenient way for you to sync your agenda with your mobile device (I use Git, but you could invoke Bluetooth, KDE Connect, Nextcloud, or your file syncronization tool of choice), and you have to install an Org-mode viewer (such as [https://f-droid.org/en/packages/com.orgzly/](Orgzly)) and 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 gets reflected on your mobile so that you stay organized even when Emacs isn't available. ![Calendar](orgzly-agenda.jpg) Intrigued? Read my step-by-step guide about [Calendaring with Org-mode and Git](https://opensource.com/article/19/4/calendar-git). ## Terminal There are [lots of terminal emulators](https://opensource.com/article/19/12/favorite-terminal-emulator) available, and admittedly the elisp terminal emulator in Emacs isn't the greatest general-purpose one. However, it's got two notable advantages: ### Opens in an Emacs buffer I use Emac's elisp shell because it's convenientnly located in my Emacs window, which I often run in fullscreen. It's a small but significant advantage to have a terminal just a ``C-x o`` away, and it's especially nice to be able to glance over at it for status reports when it's running a lengthy job. ### Easy copying and pasting if no system clipboard is available Whether I'm being too lazy to move my hand from the keys to the mouse, or whether I don't have mouse functionality because I'm running Emacs in a remote console, having a terminal in Emacs can sometimes mean quick transference of data from my Emacs buffer to Bash. To try the Emacs terminal, type press **Alt**+**X** (``M-x`` in Emacs notation), then type ``shell``, and press **Return**. ## Racket [Racket](http://racket-lang.org) is an exciting emerging dialect of Lisp 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 program, but with a terminal instead of just a turtle. Emacs, being based on Lisp itself, makes a great IDE for advanced Racket coders. It doesn't ship with ``racket-mode`` (yet), but you can install Racket-mode and several other helper extensions yourself using the Emacs package installer. To install it, press **Alt**+**X** (**M-x** in Emacs notation) and type ``package-install``, and then press **Return**. Then enter the package you want to install, ``racket-mode``, and press **Return**. Enter Racket mode with ``M-x racket-mode``. If you're new to Racket but not new to Lisp or Emacs, start with the excellent [Quick Introduction to Racket with Pictures](https://docs.racket-lang.org/quick/index.html). ## 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 and 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. There are two popular modern Lisps, aside from elisp, that are easy to run as stand-alone scripts: ### Racket You can run Racket scripts relying on your system's Racket install to provide run-time support, or you can use ``raco exe`` to produce an executable. The ``raco exe`` command packages your code together, along with runtime support files to create an executable. The ``raco distribute`` command 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. ### GNU Guile GNU Guile (GNU Ubiquitous Intelligent Language for Extensions) is an implementation of the Scheme programming language, 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: ``` #!/usr/bin/guile -s !# (display "hello world") (newline) ``` Compile and run it with the ``guile`` command: ``` $ guile ./hello.scheme ;;; compiling /home/seth/./hello.scheme ;;; compiled [...]/hello.scheme.go hello world $ guile ./hello.scheme hello world ``` ## Running Elisp without Emacs Emacs itself 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 in your Emacs configuration, omit this option). ``` emacs -Q --script ~/path/to/script.el ``` ## Cheatsheet Many of the greatest parts of Emacs can happen without Emacs; Org-mode is a format just as much as it is an Emacs extenion, popular Lisp dialects are languages mostly independent of any specific application, and even elips can be written and run without a visible or interactive instance of Emacs. However, Emacs is an amazing tool for anyone curious about how blurring the line between code and data can lead to greater innovation and heightened efficiency. Luckily, it's the 21st century and Emacs has a GUI with traditional menus and plenty of documentation, so the learning curve isn't what it used to be. To maximize the way Emacs can benefit you, though, you're going to want to learn its keyboard shortcuts. Because every task that Emacs is capable of is an elisp function, *anything and everything* in Emacs can be mapped to a keyboard shortcut, so it's impractical to try to describe them all. The essential key combinations to learn are the ones you use ten times as often as the obscure ones. We've gathered the most common Emacs key bindings into a cheatsheet for your reference. Hang it near your monitor, or on your office wall, or use it as a mousepad. Keep it handy, refer to it often. You'll get all the time you spend learning the commands back tenfold once you start getting twice as much done in one sitting. And once you start writing your own functions, it's fair to say you won't regret having grabbed a copy of this free cheat sheet!