Skip to content

rhuid/emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GNU Emacs configuration

My extensions

Some custom functions

rh/act-inside

The command rh/act-inside (bound to M-i) kills the content of the balanced expression that contains the point and put the point inside (think of Vim’s change-inner but not having to type so long to specify the delimiter)

Suppose the current point is denoted by | and we have

(here is a "nice| string" inside)

Pressing M-i takes us to

(here is a "|" inside)

However, C-M-u M-i would have taken us to

(|)

The command rh/act-inside accepts universal argument. For instance, C-u M-i copies the content of the balanced expression instead of killing it.

rh/change-inside-forward

The command rh/change-inside-forward (bound to M-I) does the same as rh/act-inside but for the next balanced expression. Suppose we have

my fruits |are "apple", "mango" and "guava"

Then pressing M-I takes us to

my fruits are "|", "mango" and "guava"

To jump several balanced expressions ahead, we supply prefix argument. For instance, typing a fruit (say, banana) and pressing C-2 M-I takes us to

my fruits are "banana", "mango" and "|"

To jump back, we supply negative argument. For instance, typing another fruit (say, papaya) and pressing C-u -2 M-I takes us to

my fruits are "|", "mango" and "papaya"

rh/copy-sexp-at-or-around-point

In my config, this command is bound to C-M-w (by default, Emacs binds append-next-kill to this key, which I have rebound to C-M-S-w). This commands checks if the point is at the start of a balanced expression. If it is, then the expression is copied. Otherwise, it copies the smallest balanced expression that contains the current point.

Invoking C-M-w, in the following case, copies the whole string.

"My GNU/Linux opera|ting system."

Prefix argument is supplied to specify how many balanced expressions to copy. For instance, invoking C-3 C-M-w, in the following case, copies all the three strings.

"G|NU" "Emacs" "thermonuclear editor"

rh/forward-opening-delimiter

Moves the point to the next opening delimiter. Prefix argument signifies how many opening delimiters to move forward.

rh/backward-opening-delimiter

Moves the point to the previous opening delimiter. Prefix argument signifies how many opening delimiters to move backward.

rh/mark-whole-line

When there is no active region, this commands marks the whole line. Otherwise, it extends the active region by a whole line at the end opposite to the point. For instance, if the point is at the lower end of the active region, this will extend the region by a whole line above and vice versa.

rh/join-line

This is a more sensible join-line based on the built-in join-line. Also takes prefix argument to join multiple lines.

rh/break-sentence

This command starts the next sentence in a new line and moves the point there. Also takes prefix argument to break multiple sentences.

rh/unwrap-parent-sexp

This removes the delimiters of the smallest sexp containing the current point. If you are already at the beginning of the target sexp (balanced expression), use the built-in delete-pair instead. A prefix argument can be used to climb up the parent sexp hierarchy. For instance, suppose we have the following.

mylist = ["Emacs", "Dired", "Esh|ell"]

With prefix argument C-2 (or C-u 2), we end up with the following.

mylist = "Emacs", "Dired", "Esh|ell"

Other things

  • To enable Emacs keybindings for all GTK text fields (including Firefox), run in shell:
gsettings set org.gnome.desktop.interface gtk-key-theme "Emacs"

Early Init

Emacs loads early-init.el file before init.el. This following marks the start of the early-init.el file.

;;; early-init.el --- Load this before init.el -*- lexical-binding: t; -*-

Defer garbage collection

Garbage collection is important but may slow down Emacs startup slightly. The following defers garbage collection to speed up startup.

;; Defer garbage collection
(setq gc-cons-threshold most-positive-fixnum
      gc-cons-percentage 0.6)

Set default-frame-alist

It’s important to set default-frame-alist early as this affects the how the Emacs frames start and look like. Here, we set the font to Iosevka, sized 15. We start Emacs in fullscreen, maximized.

(setq default-frame-alist '((font . "Iosevka Term-15") (fullscreen . maximized)))

Disable UI elements

By default, Emacs starts with several GUI elements (menu bar, tool bar, scroll bar). These are unnecessary and look polluting in a minimalist setup.

;; Disable UI elements
(menu-bar-mode   -1)
(tool-bar-mode   -1)
(scroll-bar-mode -1)
(tooltip-mode    -1)
(set-fringe-mode -1)

Inhibit startup annoyances

By default, Emacs also pulls in lots of extra baggage at startup. To get a cleaner startup, we inhibit a lot of theses baggage.

  • Setting inhibit-startup-screen to t inhibits the default Welcome to GNU Emacs startup screen. Now Emacs will start with the *scratch* buffer.
  • To not load default.el from the Emacs installation directory, we set inhibit-default-init to t.
  • Setting inhibit-x-resources to t inhibits loading X resources.
  • Setting frame-inhibit-implied-resize to t stops Emacs from automatically resizing frame when changing font or UI elements.
  • Setting server-client-instructions to nil makes client sessions cleaner.
  • Setting emacs-start-time to current-time records the time Emacs started, for profiling startup time later.
  • Setting warning-minimum-level to error inhibits auto pop ups of warning buffer unless it’s an error. The value could be emergency (Emacs warns you only when there is an emergency).
  • The line (fset 'display-startup-echo-area-message #'ignore) suppresses the echo area message shown at startup.
;; Inhibit startup annoyances
(setq
 inhibit-startup-screen  t
 inhibit-default-init    t
 inhibit-startup-message t
 inhibit-x-resources     t
 inhibit-compacting-font-caches t
 inhibit-startup-echo-area-message t
 frame-inhibit-implied-resize t
 server-client-instructions nil
 emacs-start-time (current-time)
 warning-minimum-level :error)

(fset 'display-startup-echo-area-message #'ignore)

Native compilation tweaks

In newer versions of Emacs, native compilation is on by default. The following code make some adjustments to how Emacs native compiles the source files.

;; Native compilation tweaks
(setq package-native-compile t
      package-install-upgrade-built-in t
      native-comp-deferred-compilation t
      native-comp-warning-on-missing-source nil
      native-comp-async-report-warnings-errors nil
      native-comp-speed 3
      native-comp-defer t)

Then we end the early-init.el file with the following file.

(provide 'early-init)

More Emacs ways

Swap two sexps/words

  • Set mark and deactivate (C-SPC C-SPC) at the beginning of the first sexp.
  • At the beginning of the second sexp, do C-0 C-M-t.
  • The same works for words with either C-M-t or M-t.

Transpose at a distance

  • C-u ARG M-t takes the word before or around point and drags it forward past ARG other words (backward if ARG negative).
  • The same for transposing sexps, but here the point must be between the sexp and not in the middle of a sexp to be transposed.

Tr

About

Extensions and configuration files for the thermonuclear text editor

Topics

Resources

Stars

Watchers

Forks