Tuesday, September 26, 2023

Together: The Old And New Work Much Better!

Together: The Old And New Are Much Better!

1. Executive Summary

Emacs has had long-standing features like outline-mode and outline-minor-mode that often get forgotten in the face of newer affordances like org-mode. At the same time, Emacs continues to acquire new features — in this article, I am specifically alluding to repeat-mode. The combinatorial explosion that is the result of the various ways of bringing these together is mind-boggling — and often the result is that one fails to take advantage of what has become possible. The result is that one ends up sticking to one's long-established habits at the risk of failing to significantly enhance one's productivity.

2. Background

  • Structured navigation is a significant productivity enhancer — especially in my case since I rely exclusively on an auditory interface.
  • The above applies to both textual documents and programming source.
  • Starting all the way back in 1991, I started using folding-mode to organize code into hierarchical containers that could be expanded and collapsed; and this is what makes Emacs' eco-system amazing; folding-mode still works and is available on melpa in 2023.
  • About a year ago one of the Emacs maintainers (Stefan Mounier) helped me update portions of Emacspeak, and in the process pointed out that I could just use outline-minor-mode to expand and collapse sections of code in .el files.
  • At the time I filed this away for later use — I was still reluctant to abandon the 30+ year investment in folding-mode.
  • About a year ago, I discovered repeat-mode in Emacs and started leveraging it for everything — including outline-mode and org-mode amongst others.
  • Despite the years of investment in folding-mode, it had one drawback; keeping the fold-marks (special comments) in sync was always a bit of a hastle.
    • Bringing The Old And New Together

      This week I brought all of the above context together to:

  • Cut over the Emacspeak codebase to stop using folding-mode.
  • Turning the fold-marks to comments that outline-minor-mode understood was a trivial application of my typo.plPerl script.
  • I had already set up Emacspeak to use repeat-mode for the various outline modes.
  • Another annoyance with outline that I had fixed over 20+ years ago was to pick an easier to press prefix-key for outline; I use C-o.

3. The Resulting Experience

  • I can now skim the Emacspeak sources (as well as the Emacs sources of course) with very few keystrokes.
  • Example: Pressing C-o C-n navigates by section headings; when skimming, I only need to press C-o the first time thanks to repeat-mode.
  • I also bound j and k in the outline-mode keymaps to avoid having to chord when skimming — j is easier to press than C-n.

4. For The Future

  • Would be nice to enhance outline-minor-mode to understand sectioning comments in other programming languages.
    • The annoyance with the default (and unusable) prefix key for the outline modes needs to fix in Emacs core.

Saturday, September 16, 2023

Augment With Zoxide

Augmenting Emacs With ZOxide For Efficient File System Navigation

1. Background

Emacs has no shortage of multiple built-in means of navigating the file system with smart, context-sensitive and fuzzy completion. That said, there is one tool outside Emacs I have discovered in the last six months that brings something extra — Zoxide, a smarter cd built in Rust.

2. Default Usage

Once installed, zoxide works well in Emacs shells, as well as at terminals inside or outside Emacs. Read the zoxide docs for more details, but in a nutshell, this tool remembers directories you work in, and lets you jump to them by typing short, unique substrings.

3. Working In Emacs

So with zoxide installed, you can:

  1. Switch to a shell buffer,
  2. Execute a zoxide navigation command, e.g., z <pattern>.
  3. Once there, you can easily open files, launch dired etc.

    But given that opening dired on that target is what I often want, the above work-flow still involved two steps too many. So in typical Emacs fashion, I wrote a short function that short-circuits this process

4. Command: emacspeak-zoxide

Note: there is nothing emacspeak specific in what follows.

  1. Interactive command emacspeak-zoxide prompts for a pattern, then launches dired on the zoxide result.
  2. It uses if-let to advantage:
    • If zoxide is installed,and
    • There is a zoxide result for the specified query,
    • Launch dired on that directory.
    • Else, signal the appropriate error.
    • Notice that if-let expresses this clearly.
(defun emacspeak-zoxide (q)
  "Query zoxide  and launch dired.
Shell Utility zoxide --- implemented in Rust --- lets you jump to
directories that are used often.
This command does for Emacs, what zoxide does at the  shell."
  (interactive "sZoxide:")
  (if-let
      ((zoxide (executable-find "zoxide"))
       (target
        (with-temp-buffer
          (if (= 0 (call-process zoxide nil t nil "query" q))
              (string-trim (buffer-string))))))
      (funcall-interactively #'dired  target)
    (unless zoxide (error "Install zoxide"))
    (unless target (error "No Match"))))

In my setup, i bind this to C-; j which is convenient to press and is a mnemonic for jump.

Friday, September 08, 2023

Return To Control_Right Using XModmap And XCape

return to control-right using xmodmap and xcape

1. background

see previous article on dont punish your finger tips that described how to minimize chording in emacs. that article alluded to possibly using return as an additional controlright key; this article describes the implementation and things i discovered in setting it up.

the design described here was discovered by this google search.

2. overview of changes

2.1. xmodmap

add the following stanza to your xmodmap file to set up the needed keys:

! ret as ctrl_r
 remove control = control_r
 keycode 0x69 = return
 keycode 0x24 = control_r
 add control = control_r

2.2. xcape

next, have xcape emit controlr when return is held down:

control_r=return;\

you can find the complete implementation below:

3. lessons learn

  • 1. the above works — i can now hold down return with my right hand when hitting keys like a with my left; this makes my fingers happy.
  • one issue that i failed to fix — though unimportant except for my curiosity:
  • the controlr key on my laptop has now turned into a return key, it produces return in all cases, i.e., whether tapped or held-down.
  • i still continue to find xmodmap confusing — though that is likely my fault, and not that of xmodmap.

date: 2023-09-08 fri 00:00

author: t.v raman

created: 2023-09-08 fri 08:54

validate

Saturday, September 02, 2023

Emacs Ergonomics: Dont Punish Your Finger Tips

Emacs Ergonomics: Dont Punish Your Finger Tips

1. Summary

A collection of keybinding changes I have arrived at over time to protect my fingers.Note that I have now used Emacs for more than 33 years, and some of these changes may well have helped me much earlier; on the other hand, I likely didn't notice these issues because my hands then were not the same as what they are now.

See earlier articles on this topic for context:

So to summarize, my Emacs uses:

  1. CapsLock as Control.
  2. Using XCape, quickly releasing Control emits C-e — the eEmacspeak prefix-key.

2. Next, Some Finger Tips

Note: I'm not a trained ergonomist; the following are observations based on my experience and may not apply to everyone; I suspect the size of one's hands, the width of the keyboard etc., all matter. For the last 3+ years, I've exclusively used a laptop keyboard, in my case a Lenovo.

  1. I now find that replacing key-chords by a sequence of non-chords makes my hands happier. The trick is to replace a chord by no more than 2 keys.
  2. Since Caps lock (left pinky) is my Control key, C-s is not as nice as C-l; notice that the former requires chording with two fingres of the same hand, whereas the lattre spreads the work among both hands on an English qwerty keyboard.
  3. One work-around for the above might be to have RET emit Control if held down, but I haven't done that (yet).
  4. On the left-hand, chords that require extending or scrunching one's fingres when hitting a chord are more painful. Thus, C-z and C-x are more painful to hit than C-d. Emacs hardly uses C-z and C-c; but unfortunately, C-x is an important prefix key in stock Emacs.

3. Now For The Finger Tips

  1. I have left-shift and right-shift emit C-s and C-r using XCape.
  2. I bound C-l to ctl-x-map (still experimental). This remapping fails to take effect in places like Dired and Gnus.
  3. I additionallly bound find-file to C-; o.
  4. A long time ago, I discovered M-m (back-to-indentation) and I never hit C-a to move to the start of the line.
  5. When I remap things, I never take away the original Emacs bindings; I only provide alternatives.
  6. I use C-,, C-., C-;, and C-' as prefix keys. Downside: these only work under X, but the time where I only ran Emacs in a terminal are long gone.

See my Emacs Startup File for the setup.

4. Conclusion

There's likely a lot more to be discovered in this context; time will reveal all!

Date: 2023-09-01 Fri 00:00

Author: T.V Raman

Created: 2023-09-02 Sat 19:28

Validate