Example of Eshell Use and Thoughts On Eshell

While it may not be possible to live in Emacs 24/7, I am trying to do more things in Emacs. Part of that is using more Eshell.

For each story or defect I would get, I would make a directory with notes and I would backup the files. I have blown away local changes a few times, so I usually make sure that no longer happens. (This past week I lost some files when Windows deleted some files after a forced restart.) Once the story or defect has been released to production, I delete the local backups.

I used to use Notepad++, now I use Emacs. I take the steps and/or subrequirements and make them into a TODO list, making it easier to track progress.

For copying the files, I would make a .bat file, with aliases for directories. I would copy the files to a common directory, and append a number between the name and the extension. SomeFile.java would be copied to SomeFile.002.java, etc. I would edit the file by hand, adding files as I changed them, and incrementing the version number each time. I would then run the file in a DOS window.

Since I started keeping notes in Org, I started copying the files in Eshell. I also added some commands to put a message into a text file. I would edit as needed, and then use set-mark-command and copy-region-as-kill to highlight and copy my commands, then yank them in the Eshell buffer. There might be a way to put it all in an Emacs Lisp file, or use looping and a list, but one step at a time. Switching between buffers is more convenient than switching between applications.

The Eshell version also makes a new directory for each iteration, and moves the files there.

Here is an example, with names changed to protect the innocent (names provided by Random Word Generator):


(setenv "VER_NUM" "006")
(setenv "DATE_STRING" (format-time-string "%Y-%m-%d_%H.%M.%S"))
(setenv "COMMIT_MSG" "advance digress cave committee trouser")
(setenv "STORY_NUM" "CULTIVATE-7659")
(setenv "ARCHIVE_DIR" (concat "C:/EKM/stories/" (getenv "STORY_NUM")  "/files"))
(setenv "JAVA_SRC_DIR" "D:/genetic/jurisdiction")
(setenv "SURFACE_PKG" "src/org/partner/sausage")
(setenv "NORTH_PKG"  (concat (getenv "JAVA_DIR") "/" (getenv "SURFACE_PKG") "/west/habit/mosquito"))
(setenv "WOLF_PKG"   (concat (getenv "JAVA_DIR") "/" (getenv "SURFACE_PKG") "/option/drawer/highlight"))
(setq FILE_DIR (concat (getenv "ARCHIVE_DIR") "/files_" (getenv "STORY_NUM")  "_" (getenv "VER_NUM")))
(setenv "COMMIT_FILE" (concat (getenv "FILE_DIR") "/message." (getenv "DATE_STRING")))
cd $ARCHIVE_DIR
cp -v C:/EKM/stories/$STORY_NUM/menu.delete.highway.option.escape_workload.sql $ARCHIVE_DIR/menu.delete.highway.option.escape_workload.$VER_NUM.sql
cp -v $JAVA_SRC_DIR/$NORTH_PKG/PeelBuilder.java          $ARCHIVE_DIR/PeelBuilder.$VER_NUM.java
cp -v $JAVA_SRC_DIR/$NORTH_PKG/WaterFactory.java         $ARCHIVE_DIR/WaterFactory.$VER_NUM.java
cp -v $JAVA_SRC_DIR/$WOLF_PKG/MushroomAdapter.java       $ARCHIVE_DIR/MushroomAdapter.$VER_NUM.java
cp -v $JAVA_SRC_DIR/$WOLF_PKG/WheatBridge.java           $ARCHIVE_DIR/WheatBridge.$VER_NUM.java
cp -v $JAVA_SRC_DIR/web/WEB-INF/conf/tiles-defs-case.xml $ARCHIVE_DIR/tiles-defs-case.$VER_NUM.xml
cp -v $JAVA_SRC_DIR/$SURFACE_PKG/common/properties/ApplicationResources.properties $ARCHIVE_DIR/ApplicationResources.$VER_NUM.properties
mkdir $FILE_DIR
mv -v $ARCHIVE_DIR/*.$VER_NUM.* $FILE_DIR
(write-region (concat (getenv "DATE_STRING") ": " (getenv "COMMIT_MSG")) nil (getenv "COMMIT_FILE"))

There is a good article on Eshell on Mastering Emacs. The author and a few commenters lament that Eshell is not well documented. At least one commenter wrote that the article should be incorporated into the Emacs documentation.

There actually is an Eshell manual: you can find it at this page. The list of built-in commands is here. If you look on the Emacs documentation page, there is a list of four links. As of 2023-08-12, they are: GNU Emacs manual, An Introduction to Programming in Emacs Lisp, Emacs Lisp Reference Manual and Other Emacs manuals. The Eshell manual is listed on the page at the “Other Emacs manuals” link. [Note 1]

That page has a lot of manuals. It has links to the other three main manuals, as well as the parts of Emacs not covered in the primary manual: Calc, Eshell, IDO, Org (which is the same as the manual on the Org mode site), Tramp, use-package, and many more. I always went to the primary Emacs manual, and I do not think I had ever looked at the page for the other manuals until I did so by chance a few days ago. I wonder why the manual for Hyperbole is not on the list.

One of the comments on the Mastering Emacs article links to the Eshell page on EmacsWiki. That page has a few gems not in the manual, like for loops. I downloaded the manual source, and grepped with grep -in ‘for.*in\s’ eshell.texi, and I did not see what looked like a for loop.

I also used it on my Windows machine for work. On Linux, Emacs uses the system grep tool when I select M-x grep; this does not work on Windows since there is no grep command by default. Using grep on Eshell on Windows seems to work recursively, but not on Linux. When I did a grep in Eshell on Windows, it added each file it scanned to the list of buffers. It did choke on a large PDF file. I have not the same type of files on my work laptop as I have on my own machine, so my tests are just prelimiary; most of my files on Windows are Office files, large PDF files and large XML files that are all one line.


Note 1: It is not clear to me from the text and comments on the Mastering Emacs article if people are unaware of the Eshell manual, or if they do not think it has enough information to be useful. Nevertheless, I recommend reading all the articles on that site and the book.

This post was created in Emacs with Org Mode and Love. You’re welcome.

Image from the Hidda Codex, an 11-century manuscript housed at the Archbishop’s Diocesan and Cathedral Library in Cologne, Germany, allowed under CC BY-NC 4.0.

Alternatives to Org (that I will not be using)

One of the items in my ever-growing to-do list in Org Mode was to look at other outlining software. I think I started the list with the intent of trying these out, but as it grew I just kept track of new programs as I came across them. I have decided to abandon this list since I think Org and Emacs will fit whatever needs I have now and in the future. Plus I kept finding other alternatives to Org (either as outliners or for to-do lists), and since the list got longer and longer, I just decided to scrap the idea. Here I will just list what I found.

  • Leo Editor
  • Todo.txt
    • Main page.
    • Neil Van Dyke’s page on Todo.txt. He also has a page on Emacs packages he has written.
    • Emacs mode for Todo.txt.
  • TaskWarrior
    It looks like this requires a separate server to run.

  • A Plain Text Personal Organizer. This is more of a system, and there does not seem to be an application.
  • [x]it (I guess pronounced like “exit”)
    I looked at the syntax guide for about a second, and decided I did not need to read any further. With Org, you can set the status of an item with a word (like “TODO”, “INPROGRESS”, “CANCELLED”, “DONE”); I think you can add your own if you want. Using punctuation for that is inefficient. I do not need yet another thing to remember. I prefer thinking in words rather than symbols, and I prefer context being somewhere other than in my head.

One of the Hacker News discussions on xit had a comment that made me realize there was not much point in keeping this list:

If you want a plain text organizational, compositional and scheduling tool that you can use for the rest of your life and know that 30 years down the line it will be actively supported, developed and you will be able to tweak anything you want…. emacs/org mode is by far and away the best choice. It isn’t even remotely close, we are talking about the difference between a planet and a tiny asteroid when you compare org mode to other plain textish organizational, compositional and scheduling tools.

For as long as humanity doesn’t collapse and probably even after it does org mode and emacs will be used (there is going to be some nerd somewhere using org mode and ledger cli to meticulously track how many smoked rats and cockroach kebobs they have left to eat before they have to leave their bunker), there is just such an intense critical mass of utility under an open source license.

WRT outliners: I do not create plain text files anymore. I just make everything an Org file, and collapse parts that I am not interested in looking at in any given moment. When you have a tool that can do anything, why use anything else?

You’re welcome.

Image from an 11th-century manuscript made at the monastery of St. Gall, housed at the Jagiellonian Library (Wikipedia page here), image from e-Codices, assumed allowed under CC BY-NC 4.0.

Tracking Tax Documents And Other Ideas For Learning Org Mode

Whenever Emacs or Org mode is mentioned on Hacker News, there is usually at least one comment from someone who said they started learning it, but had a hard time sticking with it. It is easier to learn a new technology if you have a goal to use it for something, especially something non-technical. “I want to learn Rails/Phoenix/etc to make a web app to keep track of $SOMETHING-IN-PARTICULAR” is better than “I want to learn Rails/Phoenix/etc”. They could learn Emacs and/or Org if they had a reason to learn them. Here are a few ideas on things you can do to learn Org. It doesn’t have to be a major project.

Right now it is tax time in the United States. They have to be filed with the Internal Revenue Service by April 15. Employers, HSAs, banks and brokerages have been sending out a LOT of forms. You could make a simple checklist for each of the forms you get, and check them off as you get them. Or make them TODO headings, and mark them as DONE as they arrive; this will add a timestamp. Plus: You can make this outline into a template, and re-use it next year.

I think there is a way to make templates in Org using something called Capture, based on what I have read about it. At some point I will read the Org manual or finish Rainer Koenig’s Org-mode course on Udemy. I only finished half of it, and I still got a lot out of it. Right now when I need to re-use a list, I make a template, and when I need a new one, I put it in the kill ring with org-cut-subtree, and I call org-paste-subtree twice: Once to bring back the template, and a second time to have a copy as an instance.

I also have a list of repeating tasks for things that I need to do every month: pay rent, pay electric bill, pay the water bill. I have monthly tasks for backing up my GnuCash files and my KeePassXC files, and I bundle my Org files and put them on thumb drives. I also have tasks for my car: getting my oil changed, and for replacing different fluids. I have yearly goals for bills that I pay once a year: web hosting, mail box, some insurance.

If you make repeating tasks, look in setting the org-log-into-drawer variable. A “drawer” in Org is a section that is hidden by default, but can still be viewed by calling M-x org-cycle.

I just started Org by making to-do lists, and learned more over time.

You’re welcome.

Image from Hillinus Codex, Cod. 12, an 11-century manuscript housed at the Archbishop’s Diocesan and Cathedral Library in Cologne, Germany, allowed under CC BY-NC 4.0.

Starting Org Mode

I have started trying out Org mode.

Granted, this is not the first time. But this time I am going to go slowly. I keep reading posts from people that Org changed their life, and my life certainly needs changing. My ideal job would involve no Microsoft products at all (do not assume I am an Apple user when I say that). I need to learn more about the useful tools if I want that to happen.

So far there is not much to report. I am making a text file with commands and keybindings as I learn them. I will eventually put it on my site for my own reference. If other people find it useful, that’s great. At every job I have ever had, there are always a lot of people who want to keep everything in their heads. It’s like there is some contest to see who can keep the most mental plates spinning. I really hate playing that game. Hopefully, Org mode can reduce my cognitive burden.

You’re welcome.

Image from Minuscule 585, a 10th-century manuscript housed at the Biblioteca Estense; image from Wikimedia, assumed allowed under Public Domain.

Emacs Tricks With Go

I am still going through some Go tutorials. I am using Emacs as my editor.

There are some things that the go mode does not handle well; I don’t know if this is a shortcoming in the mode, or if I am using an old version, or if there is some conflict with another mode I am using. It’s actually a minor point.

It does not indent switch statements the way I want. All the “case” statements and everything inside them is indented as far as the “switch”. Hitting tab does not work. I have to hit “space” for every line. It gets pretty tedious.

But I found a way to do it:

  • set-mark-command (C-@) and highlight the region
  • indent-rigidly (C-x TAB)
  • hit the arrow key as many times as I need. This will indent all the lines the same amount.

 

I also learned something about opening files. I had a directory with a file called “time.go” and “showtime.go”. When I tried find-file (C-x C-f), or switch-to-buffer (C-x b), it kept picking up “showtime.go”, even though I wanted “time.go”. I was able to open “time.go” with find-alternate-file (C-x C-v). Then I had to re-open “showtime.go”. It’s not a perfect solution, but it worked for me.

These commands are not unique to the Go mode.

You’re welcome.

Image from a late 9th- or early 10th-century Gospel manuscript made at the monastery of Saint Gall in eastern Switzerland, manuscript housed at Bavarian State Library, webpage information here, image from World Document Library, image assumed allowed under Fair Use.

A Hacker News Comment About Emacs

I have started using Emacs a bit more lately. I spent a bit of time upgrading packages and getting CIDER to work. I would like to share a comment that was left by someone  going by “maehwasu” (perhaps a disciple of Deganawida) on Hacker News on August 26, 2015 (or whatever day was 818 days ago from today).

OP is getting hate, but I write a lot of Clojure code in Emacs, and I find the following commands cover 97%+ of my usage, maybe more. For config I use Emacs Live out-of-the-box, and remap Command on OSX to be my Ctrl. That’s it.

C-a, C-e, C-b, C-f, C-p, C-n, C-v, M-v for line/screen maneuvering.

C-o for Ace-jump to go to the start of any words I see on the page.

C-d to delete. C-s to search for words not on the page.

C-k, C-y, and also how to use them with paredit to yank whole s-expression chunks.

Buffer switching and killing.

File saving and opening.

I teach the above to any friends who want to learn Emacs/Clojure/LISP, leaving out a few other features like whole word deletion and more advanced paredit. With halfway decent aptitude and a little practice, they become productive very quickly (within a few hours, which is a pretty good investment relative to “normal” text editors in my book).

Note: I have a post on Emacs buffers here.

You’re welcome.

Image from a 10th-century Greek manuscript housed at Fondation Martin Bodmer (Wikipedia page here), image from e-Codices, assumed allowed under Fair Use.

Notes On Using Emacs Buffers

A few keyboard commands to use multiple buffers in Emacs:

C-x d to go to a dir
use arrows and enter to navigate to where you want to go
Buffers:
C-x C-b to list buffers
use arrow keys to select a buffer
hit return to go to that buffer
hit "d" on the line of each buffer you want to delete
hit "x" to perform actions
Windows:
C-x o to go to a different window
C-x 1 (number) to make that the only window
C-x 0 (zero) to close current window
C-x 2 to split vertically

2020-09-20 Note:

In Emacs, a “window” is another emacs file open in the same terminal. It does not mean “window” in the sense of another open application on your system. You can have multiple buffers open, but only one or two showing in emacs windows. What is called a “window” in other contexts (like OSes) are called “frames” in Emacs. Here is a question on the Emacs Stack Exchange with a picture explaining it (archive.ph link here).

Usually, buffers are files. But there is also a help buffer, a messages buffer, and sometimes other buffers. For example, if you working with some variant of Lisp, you can hook your REPL into Emacs, and there could be a buffer running your REPL.

You can also list the buffers using M-x list-buffers. One difference is that C-x C-b will open the list in the same window if you only have one window showing. M-x list-buffers will open a second window if you only have one showing.

You’re welcome.