Sunday, August 2, 2026

Some emacs lisp utilities that have been useful for me.

Several utilities to ease the pain of working with a  single monitor 

 

[UPDATED October 16, 2026 with more utilities, and some edits on the lisp utilities.]

Working on a small monitor, like a laptop screen, can be a strain.  To make this easier, I wrote some utilities in emacs lisp.  Another one was written by someone named "Gildea" on a mailing list.  They have been useful to me; perhaps they will be useful to others.  They are simple, and certainly could be improved upon. 
 
First open a second window, horizontally (\C-x3).  Then use the first function to enlarge one of the windows horizontally.  It is hardwired to enlarge, horizontally, by 20 character widths; this can be edited, and perhaps ideally, a means would be incorporated into the code to query the user for a desired number of characters or width.  One can just as easily change the sizes of windows by dragging with a mouse.
 
One caveat.  Recently, many little windows seem to appear on the lower edge of the frame.  I freely admit that I have not taken much time to figure this out, but it's an extremely problematic issue.  For the work flow enabled by these utilities, these small windows interfere.   
 
It is useful to make one window much larger---an editing window. 
 
A useful enhancement might be to allow three or more windows to be open.  Maybe I'll try to understand windmove.el at some point.  
 

I.   Enlarge one of two horizontally split windows

(defun enlarge-window-very-horizontally ()
  "Enlarge this window horizontally."
  (interactive)
  (enlarge-window-horizontally 20))
 

II.  Flip flop: Move to other window and swap widths.

This utility does two things: it moves the cursor to the other window; and it swaps the sizes of the two windows.    
 
(defun flip-flop-and-change-horizontal-windows ()
  "Swap HORIZONTAL window sizes; move into the other window.  This function
enables one to have two windows visible, but with one very narrow."
   (interactive)
   (let ((current-window-width (window-width)) 
     (new-window-width nil)
     (delta-window-width nil))
     (other-window 1)
     (setq new-window-width (window-width))
     (setq delta-window-width (- current-window-width new-window-width))
     (enlarge-window-horizontally delta-window-width)))

 

 III.  Flip flop vertically (like the above)

This version works with vertically split windows.  This might work better in some cases.  These utilities are minimal, written by a naive emacs user.  I feel certain they can be modified and improved in various ways.  I would like to find a way that the tool above, for horizontally split windows, can move back and forth, even when either or both sides is split into two or more windows vertically.  They sky's the limit, but these utilities are simple, and therefore easy to use and remember.

 

(defun flip-flop-and-change-windows ()
  "Swap window sizes; move into the other window.  This function
enables one to have two windows visible, but with one reduced to two lines."
   (interactive)
   (let ((current-window-height (window-height)) 
     (new-window-height nil)
     (delta-window-height nil))
     (other-window 1)
     (setq new-window-height (window-height))
     (setq delta-window-height (- current-window-height new-window-height))
     (enlarge-window delta-window-height)))

 

IV.  Swap positions of two windows with contents. 

 Another tool was written by a "Gildea" on a mailing list in 1988, possibly in answer to a query of mine.  It enables one to just swap the positions of two whole windows. 
 
 (defun swap-window-positions ()
  "Swap the positions of this window and the next one.
(credit to gildea Nov 88)"
  (interactive)
  (let ((other-window (next-window (selected-window) 'no-minibuf)))
    (let ((other-window-buffer (window-buffer other-window))
      (other-window-hscroll (window-hscroll other-window))
      (other-window-point (window-point other-window))
      (other-window-start (window-start other-window)))
      (set-window-buffer other-window (current-buffer))
      (set-window-hscroll other-window (window-hscroll (selected-window)))
      (set-window-point other-window (point))
      (set-window-start other-window (window-start (selected-window)))
      (set-window-buffer (selected-window) other-window-buffer)
      (set-window-hscroll (selected-window) other-window-hscroll)
      (set-window-point (selected-window) other-window-point)
      (set-window-start (selected-window) other-window-start))
    (select-window other-window)))



 I hope these are useful, as they have been useful to me.
 

Setting Font Styles in LaTeX  

These are extremely simple functions.  They have been useful to me.
 
I.  Set region in Italics.
 
 (defun ltx-italicize-region (begp endp)
  "For LaTeX.  Called with point and mark at beginning and 
   end of region to be typeset in Italics. LaTeX style."
  (interactive "r")      ;; save point and mark.
  (save-excursion
    (goto-char endp)
    (insert "\\/}")
    (goto-char begp)
    (insert "\\textit\{")))


II. Set region in Boldface type.
 
(defun ltx-boldify-region (begp endp)
  "For LaTeX.  Called with point and mark at beginning and 
   end of region to be typeset in boldface.   Latex style."
  (interactive "r")      ;; save point and mark.
  (save-excursion
    (goto-char endp)
    (insert "\}")
    (goto-char begp)
    (insert "\\textbf\{")))

 
III. Set region in Slant type. 
 
 (defun ltx-slantify-region (begp endp)
  "For LaTeX.  Called with point and mark at beginning and 
   end of region to be typeset in slanted type. LaTeX style."
  (interactive "r")      ;; save point and mark.
  (save-excursion
    (goto-char endp)
    (insert "\\/}")
    (goto-char begp)
    (insert "\\textsl\{")))


IV.  Set region in Smallcaps.
 
(defun ltx-smallcap-region (begp endp)
  "For LaTeX.  Called with point and mark at beginning and 
   end of region to be typeset in smallcaps. LaTeX style."
  (interactive "r")      ;; save point and mark.
  (save-excursion
    (goto-char endp)
    (insert "\\/}")
    (goto-char begp)
    (insert "\\textsc\{")))

 
 

No comments:

Some emacs lisp utilities that have been useful for me.

Several utilities to ease the pain of working with a  single monitor    [UPDATED October 16, 2026 with more utilities, and some edits on the...