Pages

Sunday, July 5, 2026

Emacs Carnival July 2026 -- Programming

I don't think of Emacs as an IDE or even a programming environment unless I'm writing Lisp to automate Emacs. Instead, I consider Emacs to be a text editor with some useful extras.

Syntax highlighting (font-lock-mode) is a nice extra. It might seem strange that I consider syntax highlighting to be an extra. If you've used a text editor 40 years ago, you'll understand why -- text editors didn't have the feature. Syntax highlighting was the purview of the compiler tool. My first experience with syntax highlighting was with Borland Turbo Pascal; I used Borland Turbo C soon after. (I think Borland's Turbo Assembler, TASM, had the feature, too.)

According to packages-selected-packages, these are the programming modes I have configured:

  • basic-mode
  • csv-mode
  • gnuplot
  • matlab-mode
  • powershell
  • python and python-mode
  • Swift mode

I don't program in Swift. Perhaps the package is a dependency for another mode. Or maybe I was ambitious one day and thought I'd try another programming language.

Is csv a programming language? If you automate the generation of spreadsheets. it's nice to have some help. But to be honest, I've not used it very often.

Easy access to shell is another nice extra. I have two functions to make use of it when I write batch files. They execute either the current line (exeln) or the entire buffer (shellfn) with some sort of shell command; they are shown below. The Windows binary uses cmdproxy.exe from MinGW -- it works out-of-the-box. But I use the Windows start program for shellfn because it invokes the correct executable based on the file's extension. Thus, Python runs a .py file; cmd, a .bat; Octave, a .m file.

;; This is bound to C-c x
;; Many thanks to Sebastián Monía for suggesting many improvements
(defun exeln (arg)
  "Execute  current line as a shell command.
With prefix ARG, run asynchronously."
  (interactive "P")
  (funcall (if arg
               #'async-shell-command
             #'shell-command)
           (thing-at-point 'line t)))

;; This is bound to C-c s
(defun shellfn ()
  "Invokes the shell using the current buffer file name as a parameter."
  (interactive)
  (shell-command (concat "start " (buffer-file-name))))

I've tried to use source blocks in Org, but I prefer putting each code snippet into its own dedicated file. Why? One reason is because I don't want the code to execute with org-mode active. Another reason is that indentation doesn't work properly. Switching modes fixes both issues, but it gets annoying very quickly. This is a topic for another post.

I look forward to seeing how other folks use Emacs for programming.

Friday, July 3, 2026

Circumvent LibreOffice Macros with Templates

Instead of writing LibreOffice macros to change a default behavior, consider customizing the default template.

Creating macros is fun for me. But I agree, automating LibreOffice with macros is daunting, and the recorder is a poor way to begin writing code.1

Recently I wanted to change the default anchor position of an image. When I insert an image by pasting, I want its anchor is to be "As Character" as opposed to paragraph, which was the current default.

I tried to record the process:

  • Paste
  • F4 (properties)
  • As Character
  • OK
  • Press Enter

The recorder captured the Paste and Enter keys well. Unfortunately, it choked on the macro's primary element -- applying the As Character property.

But then I wondered, "Can the default anchor position be set to "As Character" in Options?" "No, it cannot," I answered.2 "But you can change it in the default template. Here's how:"

  • Start LibreOffice Writer. This should present a new, blank document. But if it doesn't, press Ctrl+N.
  • Press Alt+2 to open the Styles sidebar.
  • Click the Frame Styles icon. (Please see Figure 1, Frame Styles below.)
  • An image of the sidebar in which Styles is selected.  The Frame Styles button has been clicked, and the mouse pointer hovers over on the icon so that the "Frame Styles" tooltip shows.
    Figure 1 -- Frame Styles

  • Right click on Graphics and choose Edit Style... as shown in Figure 2.
  • Image shows how the interface appears after right-clicking the Graphics style element.  The context menu shows three choices: New, Edit Style and Hide
    Figure 2 -- Edit Graphics Style

  • Choose "Type" on the left. Its icon looks an anchor.
  • Under Anchor, click the radio button next to As character.
  • Review the other settings and change whatever other defaults that don't make sense to you. I recommend clicking the checkbox to lock Height to Width (aka Aspect Ratio in other applications). Mine was unchecked, and I always found myself clicking it.
  • Choose File | Templates | Save as Template as shown in Figure 3. Note this is different from doing File | Save As and then choosing the OTT file type. And yes, you will be saving the image in the template, but it can be removed later.
  • The image shows the three options after clicking File and then Templates from the menu
    Figure 3 -- Save as Template Menu Selection

  • Enter a name for the template. I entered DEMO for this How-To, but I tend to give my templates more description names that include the paper size, such as "4 x 6 index card" or "5 x 7 greeting card LS."
  • Choose a category to enable the Save button.
  • Click the checkbox labeled "Set as default template" to ensure that every subsequent new Writer document will be derived from the new template.
  • Note that these three choices (Name, Category, Default) can be changed in the Template Manager (Ctrl+Shift+N). The dialog should look similar to the one in Figure 4, below.

  • The image is a screenshot of the Save Template Dialog box, where the template name is "DEMO," the category "My Templates" is selected and the checkbox indicates that it should be set as the default template
    Figure 4 -- The Save Template Dialog Box


  • Press Ctrl+N to create a new document. Paste an image into it to test the new template. Hopefully3 you'll get the desired result.

1 "When the macro recorder is not able to solve a specific problem, the usual solution is to write code using the OpenOffice.org objects. Unfortunately, there is a steep learning curve for the OOo objects."
2 Sometimes I gain insight into a problem by splitting myself into student and teacher.
3 I write "Hopefully" because as I repeated these steps to test them, I managed to obliterate my own default template. And I couldn't seem to fix it without restarting Writer.