Showing posts with label emacs. Show all posts
Showing posts with label emacs. Show all posts

Sunday, April 05, 2026

No File Name Completion With org-insert-link? Try This

If you invoke org-insert-link (typically C-c C-l) in order to link to a local file, you might expect that pressing TAB will complete a partial path or file name.  Instead you’ll get the frustrating message “[No match].”

What you need to do instead is to invoke the command with a prefix argument like this: C-u C-c C-l. Then you’ll get the expected completion behavior with TAB.

But why is a prefix argument necessary?  It turns out that org-insert-link expects a link type at the "Insert link" prompt.  Some link types are file, bbdb, info, etc.  (To see a full list of link types, press TAB right after invoking the command, without entering anything.)

This is a powerful command.  You can, for example, enter bbd and press TAB to complete the bbdb: link type.  Then enter the first few characters of someone’s name or a business in your bbdb list of contacts, such as arth.  Upon pressing TAB, you should see completion fill in arthur.  Press again, you’ll get Arthur Dent and perhaps his email address.  Clicking on either will complete the entry.  Press ENTER to put the link into your buffer.1

Completion isn’t available for all link types.  A link to an info node, for example, has to be entered manually, although usually it’s created with org-store-link (C-c l) while point is in the info node of interest.

I encourage you to read the help for org-insert-link and org-store-link.  The two hyperlinks immediately below will take you to the online manual on gnus.org.  But if you copy the link text and yank into an org file, Emacs will open the Org manual at the page for handling links.

[[help:org-insert-link][Emacs help for org-insert-link]]

[[help:org-store-link][Emacs help for org-store-link]]

I dislike getting frustrated.  But when I’m frustrated with Emacs, I expect to learn something if I dig deep enough.  It hasn’t let me down yet.


1 This depends on whether bbdb has been loaded.  If you use bbdb and you’re not getting completion, invoke M-x bbdb and try again.

Friday, February 27, 2026

Emacs Lisp Function to Determine the Start of Engineers Week

This year, Engineers Week started on Sunday (February 22, 2026).  It always begins on Sunday of the week of George Washington's birthday. 1

Here's an Emacs Lisp function to calculate the date that Engineers Week will begin for a given year:

(defun eweek (year)
  "Returns the date on which Engineers Week begins for the year given in
YEAR.  Returns the date in the standard format for a (Gregorian)
calendar date in calendar.el, a list of integers (MONTH DAY YEAR)"
  (calendar-gregorian-from-absolute
   (calendar-dayname-on-or-before
    0 (calendar-absolute-from-gregorian (list 2 22 year))))) 
Invoking (eweek 2025) should return (2 16 2025), which was the start of Engineers Week last year.

Friday, November 28, 2025

Edit Online Forms With Emacs

If you'd rather use your own text editor to enter content into a web form, you could use and configure a browser extension to establish a link between the form field and the editor. One such extension that Google search suggests is Browser's External Editor.1

But if you use Emacs, you're probably better off with Chrome Emacs.2

Chrome Emacs is added to a Chromium browser, but you still need to add something to Emacs. That something is the mode called atomic-chrome.

atomic-chrome can be found on Melpa; you can use the Emacs package manager to add it. My personal experience is that it's necessary to start its server manually with atomic-chrome-start-server, or add (atomic-chrome-start-server) to your init file.

I find it invaluable when commenting on a LinkedIn post, which can disappear whenever your feed is updated.

I also like it as a replacement for the Blogspot post entry field, which is easily cleared with an accidental press of Ctrl-a followed by any key press. Blogspot performs an automatic backup whenever you pause typing during new post mode. But that's a worthless feature because it will backup every mistake, including one in which you replaced all content with a key press. And it offers no way to access previous backups. I'm less likely to select all text in Emacs3, but it's not impossible. As well, I could still somehow still manage to do the Ctrl-a thing in Blogspot. Nevertheless this is a nice workaround.

But in fact I've been composing new posts outside of Blogspot for years; usually I use LibreOffice Writer because... Well, come to think of it, I don't know why I use Writer when I can use Emacs. Maybe it's because with Writer, I can insert pictures and such. (And I haven't figured out how to do that in Emacs.


1 https://chromewebstore.google.com/search/Browser's%20External%20Editor
2 https://chromewebstore.google.com/detail/chrome-emacs
3 Pressing C-x h will select all characters in an Emacs buffer.

Saturday, August 16, 2025

Define Emacs as Editor in Altap Salamander

I’ve been a devotee of the Servant Salamander / Altap Salamander file manager1 for decades. I migrated from Norton Commander (NC)2 soon after I started to work on a multi-tasking OS, Windows NT.

Likewise, I’ve been a fan of the (extensible) text editor Emacs3 for decades, having given up on Brief4, eventually. While on WinNT, I stayed with Brief a long time. But I seem to recall that Brief didn’t respond well to having one of its open files changed by another application. (This rarely happened in environments that it was designed for.)

Norton’s F4 key invoked a built-in text editor to open the selected file. The Salamander F4 key is configured to use Notepad.exe to open the selected file. But it can be configured to use other editors based on the selected file’s extension. I configure F4 to use Emacs for all text-like files.

Once I open Emacs, I like to keep that instance open for as long as possible. That’s because I build up a history usage, including:

  • Regular expression searches
  • Kill ring contents
  • On-the-fly macros

Switching to a new Emacs instance is a major interruption to my workflow.

Enter Emacs server. Emacs includes a server that can open a file in a running instance when invoked from an external application, such as Norton, ...er, Salamander. This allows a user to edit new files while maintaining the previous Emacs instance.

To use this active server process feature, you’d invoke Emacs with this command5 (all entered on a single line): C:\Path_to_Emacs_bin\emacsclientw.exe -a C:\Path_to_Emacs_bin\bin\runemacs.exe

But I find that configuring Salamander’s F4 to call the Emacs server to be difficult sometimes. In fact I spent an embarrassingly long time yesterday trying to figure it out. But it’s not at all difficult if you really understand two things:

  1. Only the Emacs executable should appear in the Custom Editor Target box; any switches go into the Arguments box before the $(Name) parameter.
  2. Emacs doesn’t like file names that contain quote marks. So if there’s a space in the path to the executable, you should specify the 8.3 name and not the path seen in Explorer.6 Please see the figure below.

I’ve heard Emacs gurus advise against installing Emacs in a location other than the default. The default on Windows currently is C:\Program Files\Emacs\emacs-30.1\. And I followed that advice unfortunately. But it caused me a great deal of grief, because it forced me to surround the paths in quotes and was incompatible with the server process. On my previous computers I had been installing Emacs in C:\Users\Public\Programs, which all users have access to and conforms to the DOS 8.3 file name format. That’s why this error is new to me.

So here’s advice from a wannabe guru:

  • Follow the instructions above to configure Salamander’s F4 to invoke Emacs if you already have Emacs and Altap Salamander installed.
  • When you install Emacs, change the installation location to ensure that the path is made up of only alpha-numeric characters and that all users will have Read and Execute permisions.


1 https://www.altap.cz/
2 https://en.wikipedia.org/wiki/Norton_Commander
3 https://www.gnu.org/software/emacs/
4 https://en.wikipedia.org/wiki/Brief_(text_editor)
5 https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html
6 Eli Zaretskii, https://lists.gnu.org/archive/html/help-emacs-windows/2014-04/msg00013.html

Friday, July 28, 2023

Quarterly Reports in Org-Agenda

Org-mode comes out-of-the-box with Agenda views for these time spans: Day, Week, Fortnight (aka bi-weekly, but why?), Month and Year.  Oddly, there’s no built in option for Quarter.

Ideally, Org-agenda would come preconfigured to respond to the keystroke sequences of vq1, vq2, vq3, vq4 to display reports for Q1, Q2, Q3, Q4.

After searching online and struggling with customizations, I came across a two-step method to show a quarterly report that doesn’t require code.

First, invoke org-agenda with a prefix argument of 91 like this:

M-91 M-x org-agenda <ENTER> a

The “M-91” means you hold down the Alt key while pressing “9” and then “1” but you can also do this:

C-u 91 M-x org-agenda <ENTER> a

Second, press “j” (while visiting the *Org-Agenda* buffer) to invoke org-agenda-goto-date.  Choose the first day of whatever quarter you’re interested in.  Today I was interested in reviewing content for the previous quarter.  Thus I choose 2023-04-01 to show the second quarter (Q2) of 2023.

If you want to choose more Agenda options such as Search, Matching or other, or if you want 91 days to be the default view always, try setting org-agenda-span to 91, which will eliminate the need for the prefix argument to org-agenda.  You can do this in two ways:

Invoke M-x customize and then search for org-agenda-span

Or press C-h v org-agenda-span and then click customize.

Once you're in the customize buffer, click the Value Menu button and then enter 91, or whatever number of days you're interested in.  Note that this entry must be an integer. It can accept a negative value, but the results are undesirable.  So stick with positive integers.

Thursday, November 21, 2019

Open Org Mode Links With Default Windows Application

I've been using Org Mode for several years.

One Org Mode quirk is that the links in Org files always open in the Emacs editor, by default.  Click a link to Emacs_reference_card_v25.pdf on your hard drive and you might end up with a buffer that starts with this content...

%PDF-1.5
%    
3 0 obj
<<
/Length 4340      
/Filter /FlateDecode
>>
stream

I finally figured out a way to tell Emacs to open such "external" links with the default Windows application.  The multi-part solution involves first specifying all such links with a Special Prefix.  I chose "file:".  It's lame, I know, but it's also how you'd prefix an address for your web browser to open a local file.

So, for the PDF above, the link would look like this:
file:C:\emacs-25.2_64\doc\Emacs_reference_card_v25.pdf

The second part of the solution is to figure out which application on Windows you'd like to use to open the file "properly."  Rather than specifying multiple programs, such as a PDF reader for PDF files, a spreadsheet program for XLS/ODS, a word processor for DOC/ODT, etc., I decided that the single Windows command START already knows how to open all the programs on my computer.

If you were to enter the following in a command prompt, the program associated with the PDF extension would open the target file (assuming the file exists).

START C:\emacs-25.2_64\doc\Emacs_reference_card_v25.pdf

But there's a slight complication.  If the link contains a space or other delimiting character, you'll need to surround the file path with quotes like this: "C:\Path With Spaces\My PDF.pdf".  Unfortunately, START interprets quoted content as the title specification. Therefore, invoking the following would merely open a command prompt window with the title C:\Path With Spaces\My PDF.pdf

START "C:\Path With Spaces\My PDF.pdf"

So to get START to work as intended, you'd want to invoke it thusly:

START "DUMMY_TITLE" "C:\Path With Spaces\My PDF.pdf"

So having figured out the proper way to open file links, we create a function to implement it:

(defun ludditegeek-open-ext (path-to-media)
 (shell-command (concat "start \"ludditegeek-open-ext\" " path-to-media)))

Note that I chose to use the function name as the text for the title.  No matter, if all goes well, START will close the command prompt after it carries out the command -- most likely you'll never see the window.  For debugging, you could include the /WAIT switch, in which case you'll see the window, and the application will be listed in Task Manager with the title included.

Another thing to note here is that strings are defined in Lisp as characters enclosed in double-quotes.  But the title also requires double-quotes!  So I used a backslash character to escape the double-quote characters that are used to define the title.

The third part of the solution is to employ org-add-link-type to define the "file" link:

(org-add-link-type "file" 'ludditegeek-open-ext)

I call it with eval-after-load.  Here, finally, is what you can put in your .emacs:

(eval-after-load "org"
  '(progn
     ;; Create links in Org thusly:
     ;; [[file:/path/to/ppt.pptx][name of ppt]]
     ;; [[file:"/path with spaces/to/pdf.pdf"][name of pdf]]
     ;; [[file:/path/to/video.mkv][name of video]]
     (defun ludditegeek-open-ext (path-to-media)
       ;; Use Windows start command to open default application.
       ;; Note that first parameter to START is the command prompt window's title,
       ;; necessary for links that are enclosed in "", such as links with spaces.
       (shell-command (concat "start \"ludditegeek-open-ext\" " path-to-media)))
     (org-add-link-type "file" 'ludditegeek-open-ext)
     ))

I hope you find this useful!

Sunday, October 07, 2007

Emacs: Yet Another Cool High-Tech Thing

Two years ago, I wrote about Servant Salamander. In that post, I described how Servant Salamander substituted nicely for Norton Commander when I made the switch from MS-DOS to Windows NT.

The other software substitute I made was to replace my favorite text editor, Brief. When I started using Brief, it was by a company called "Underware." When I stopped using it, it had been taken over by Borland. They had no plans to make it Windows-compatible.

I loved Brief's ability to record and playback keyboard macros. It had undo. Its regular expression search and replace capability was powerful. It could cut and paste columns of text. It could be scripted. It supported multiple windows.

I continued to use Brief on Windows NT, even though its cut and paste didn't work with the Windows clipboard. And I recall having display problems at certain video resolutions.

So I set off in search of a new Windows text editor. The minimum requirements were:
  • Column marking, cutting, pasting.
  • Undo.
  • Regular expression search / replace.
  • Keystroke macros.
  • Windows compatible.
I wanted an editor that could be scripted. And even better, one with the same keystrokes as Brief, or with a reconfigurable keyboard.

I came across Crisp, Zeus and then Vedit a bit later.

I rejected Crisp almost immediately, even though it seemed to be the ideal replacement. The problem was that it was unstable. Or, more accurately, it made my computer unstable. So I dropped it quickly.

I was mostly happy with Zeus. But sometimes I needed to edit binary files, and one thing I did not like was that Zeus could not handle null characters. (And it wasn't 100% Brief-compatible.) That's why I got Vedit. Vedit did a great job with all kinds of files of all sizes. I was even able to edit EBCDIC files, which helped when I was writing an EBCDIC to ASCII translator. But I never got comfortable with Vedit, so I continued to use Zeus primarily.

One day I decided to try another search for the Ultimate Text Editor. Someone recommended Gnu Emacs.

Emacs was "sort of" Brief compatible. In fact, it was Crisp-compatible with its Crisp-mode Lisp add-on. But in reviewing Emacs, I came across the advice that it's best to learn the native key-mapping. So that's what I did, back in 2001.

It was a bit hard to get used Emacs, and I did have to remap the keyboard a tiny bit. For example, back then, Emacs would interpret the Del key as Backspace, which deletes the previous character instead of the next character. (This is not true of more recent versions.) Also, I stumbled over Emacs terminology. For example, it's not "Cut" and "Paste" but rather "Kill" and "Yank."

But all the effort I put in to it was well worth it. Now, I don't bother to write text-manipulation programs because it's easier (and more fun) to script Emacs to perform that kind of work. I enjoy using Emacs Planner to keep track of tasks and notes that pertain to numerous work projects. And at one time, I enjoyed using the newsreader Gnus with it's wonderful ability to score message threads based on any number of regular expression filters I could come up with.

Emacs is licensed under the GNU General Public License, which means that it's free, not only in the sense that you can obtain it without cost, but also that you are free to modify and distribute the software, provided you pass along this same freedom.

Emacs is amazing. It is constantly being improved by intelligent people who demand great things from their programs. It can run on many different platforms. Try it out!