ultronozm / spout.el

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spout.el: Speed keys for outline/foldout modes

Overview

This package provides a “speed key” minor mode for outline/foldout modes, inspired by the speed key functionality in org-mode. The idea is that when the point is at the beginning of a section heading, the user can navigate or edit the document using single keypresses.

I’ve used this only for editing LaTeX.

Note: as of March 2024, I’ve stopped using this package in favor of a functionally equivalent setup based on repeat-mode (see the definition of outline-repeat-map in my config).

Related packages

I figured there’s no harm in sharing this package, which is what I’ve been in the habit of using, but you might be better off with the following alternatives:

There’s also some overlap here with some features of the latex-extra package.

Configuration

Basic

Download this repository, install using M-x package-install-file (or package-vc-install, straight, elpaca, …), and add something like the following to your init file:

(use-package spout)

See the customization option spout-keys for key bindings, and adjust it to your liking. Then, when you want to activate this package, do M-x spout-mode. It may help to bind some global keys to outline-previous-heading and outline-next-heading (see Refined). That way, you can always quickly navigate to a heading, where the speed keys will be in effect.

Refined

Here’s something closer to my actual setup, which requires AUCTeX.

(use-package emacs
  :bind
  ("s-n" . outline-next-heading)
  ("s-p" . outline-previous-heading))

(use-package foldout
  :config
  ;;  don't want foldout to include "bibliography"
  (defun czm-tex-outline-level-advice (orig-fun &rest args)
    (if (looking-at "\\\\bibliography") 1 (apply orig-fun args)))
  (advice-add 'LaTeX-outline-level :around #'czm-tex-outline-level-advice))

(use-package spout
  :after latex
  :hook
  (LaTeX-mode . spout-mode)
  :custom
  (spout-keys
   '(("n" outline-next-visible-heading)
     ("p" outline-previous-visible-heading)
     ("u" outline-up-heading)
     ("f" outline-forward-same-level)
     ("b" outline-backward-same-level)
     ("<left>" outline-promote windmove-left)
     ("<right>" outline-demote windmove-right)
     ("<" beginning-of-buffer)
     (">" end-of-buffer)
     ("<up>" outline-move-subtree-up windmove-up)
     ("<down>" outline-move-subtree-down windmove-down)
     ("s" outline-show-subtree)
     ("d" outline-hide-subtree)
     ("a" outline-show-all)
     ("q" outline-hide-sublevels)
     ("t" outline-hide-body)
     ("k" outline-show-branches)
     ("l" outline-hide-leaves)
     ("i" outline-insert-heading)
     ("o" outline-hide-other)
     ("@" outline-mark-subtree)
     ("z" foldout-zoom-subtree)
     ("x" foldout-exit-fold)))
  :config
  (require 'texmathp)
  (defun LaTeX-skip-verbatim (orig-fun &rest args)
    (if (eq major-mode 'latex-mode)
        (let ((n 100))
          (apply orig-fun args)
          (while (and (LaTeX-verbatim-p) (> n 0))
            (setq n (- n 1))
            (apply orig-fun args)))
      (apply orig-fun args)))
  (dolist (f '(outline-next-heading
               outline-previous-heading
               outline-up-heading
               outline-forward-same-level
               outline-backward-same-level))
    (advice-add f :around #'LaTeX-skip-verbatim)))

In particular, I bind the arrow keys to windmove commands; if you don’t want to do that, then replace those commands with whatever you use the arrow keys for (e.g., forward-char, backward-char, next-line and previous-line).

About


Languages

Language:Emacs Lisp 100.0%