• Stars
    star
    807
  • Rank 56,489 (Top 2 %)
  • Language
    Emacs Lisp
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Collection of Ridiculously Useful eXtensions for Emacs

License GPL 3 MELPA MELPA Stable

crux

A Collection of Ridiculously Useful eXtensions for Emacs. crux bundles many useful interactive commands to enhance your overall Emacs experience.

Most of the crux commands are related to the editing experience, but there are also a bunch of utility commands that are just very useful to have (e.g. crux-open-with and crux-reopen-as-root).

Origins of crux

Many of the functions in crux started life as blog posts on Emacs Redux, then were included in Emacs Prelude, before finally being extracted to crux. You can see a full list of blog posts on functions in crux on the tags page.

Installation

Available on all major package.el community maintained repos - MELPA Stable and MELPA repos.

MELPA Stable is recommended as it has the latest stable version. MELPA has a development snapshot for users who don't mind breakage but don't want to run from a git checkout.

You can install crux using the following command:

M-x package-install [RET] crux [RET]

If the installation doesn't work try refreshing the package list:

M-x package-refresh-contents

Alternatively, you can add the following code to your Emacs config:

(unless (package-installed-p 'crux)
  (package-refresh-contents)
  (package-install 'crux))

Keybindings

crux doesn't setup any keybindings for its commands out-of-the-box. There are several reasons for this:

  • Most users probably won't need all the commands, so it'd be an overkill to define a minor mode consuming a lot of valuable keybindings
  • Many of the optimal keybindings are in the user space anyways (e.g. C-c some-letter)
  • Everyone has their own preferences when it comes to keybindings

Here's the list of some suggested keybindings. Feel free to bind individual commands to whatever keybindings you prefer.

Command Suggested Keybinding(s) Description
crux-open-with C-c o Open the currently visited file with an external program.
crux-smart-kill-line C-k or Super-k First kill to end of line, then kill the whole line.
crux-smart-open-line-above C-S-RET or Super-o Insert an empty line above the current line and indent it properly.
crux-smart-open-line S-RET or M-o Insert an empty line and indent it properly (as in most IDEs).
crux-cleanup-buffer-or-region C-c n Fix indentation in buffer and strip whitespace.
crux-recentf-find-file C-c f or Super-r Open recently visited file.
crux-recentf-find-directory C-c F Open recently visited directory.
crux-view-url C-c u Open a new buffer containing the contents of URL.
crux-eval-and-replace C-c e Eval a bit of Emacs Lisp code and replace it with its result.
crux-transpose-windows C-x 4 t Transpose the buffers between two windows.
crux-delete-file-and-buffer C-c D Delete current file and buffer.
crux-copy-file-preserve-attributes C-c c Copy current file with file attributes preserved
crux-duplicate-current-line-or-region C-c d Duplicate the current line (or region).
crux-duplicate-and-comment-current-line-or-region C-c M-d Duplicate and comment the current line (or region).
crux-rename-file-and-buffer C-c r Rename the current buffer and its visiting file if any.
crux-visit-term-buffer C-c t Open a terminal emulator (ansi-term).
crux-kill-other-buffers C-c k Kill all open buffers except the one you're currently in.
crux-indent-defun C-M z Indent the definition at point.
crux-indent-rigidly-and-copy-to-clipboard C-c TAB Indent and copy region to clipboard
crux-find-user-init-file C-c I Open user's init file.
crux-find-user-custom-file C-c , Open user's custom file.
crux-find-shell-init-file C-c S Open shell's init file.
crux-top-join-line Super-j or C-^ Join lines
crux-kill-whole-line Super-k Kill whole line
crux-kill-line-backwards C-Backspace Kill line backwards
crux-kill-and-join-forward C-S-Backspace or C-k If at end of line, join with following; otherwise kill line.
crux-kill-buffer-truename C-c P Kill absolute path of file visited in current buffer.
crux-ispell-word-then-abbrev C-c i Fix word using ispell and then save to abbrev.
crux-upcase-region C-x C-u upcase-region when transient-mark-mode is on and region is active.
crux-downcase-region C-x C-l downcase-region when transient-mark-mode is on and region is active.
crux-capitalize-region C-x M-c capitalize-region when transient-mark-mode is on and region is active.
crux-other-window-or-switch-buffer M-o Select other window, or switch to most recent buffer if only one windows.

Here's how you'd bind some of the commands to keycombos:

(global-set-key [remap move-beginning-of-line] #'crux-move-beginning-of-line)
(global-set-key (kbd "C-c o") #'crux-open-with)
(global-set-key [(shift return)] #'crux-smart-open-line)
(global-set-key (kbd "s-r") #'crux-recentf-find-file)
(global-set-key (kbd "C-<backspace>") #'crux-kill-line-backwards)
(global-set-key [remap kill-whole-line] #'crux-kill-whole-line)

For crux-ispell-word-then-abbrev to be most effective you'll also need to add this to your config:

(setq save-abbrevs 'silently)
(setq-default abbrev-mode t)

Using the bundled advices

crux ships with some handy advises that can enhance the operation of existing commands.

(crux-with-region-or-buffer)

You can use crux-with-region-or-buffer to make a command acting normally on a region to operate on the entire buffer in the absence of a region. Here are a few examples you can stuff in your config:

(crux-with-region-or-buffer indent-region)
(crux-with-region-or-buffer untabify)

(crux-with-region-or-line)

Likewise, you can use crux-with-region-or-line to make a command alternately act on the current line if the mark is not active:

(crux-with-region-or-line comment-or-uncomment-region)

(crux-with-region-or-sexp-or-line)

Similarly, crux-with-region-or-sexp-or-line makes a command that acts on the active region, or else the current list (or string), or finally the current line:

(crux-with-region-or-sexp-or-line kill-region)

(crux-with-region-or-point-to-eol)

Sometimes you might want to act on the point until the end of the current line, rather than the whole line, in the absence of a region:

(crux-with-region-or-point-to-eol kill-ring-save)

Minor modes

(crux-reopen-as-root-mode)

Crux provides a crux-reopen-as-root command for reopening a file as root. This global minor mode changes find-file so all root files are automatically opened as root.

License

Copyright © 2015-2021 Bozhidar Batsov and contributors.

Distributed under the GNU General Public License; type C-h C-c to view it.

More Repositories

1

prelude

Prelude is an enhanced Emacs 25.1+ distribution that should make your experience with Emacs both more pleasant and more powerful.
Emacs Lisp
5,014
star
2

clojure-style-guide

A community coding style guide for the Clojure programming language
4,008
star
3

projectile

Project Interaction Library for Emacs
Emacs Lisp
3,851
star
4

emacs-lisp-style-guide

A community-driven Emacs Lisp style guide
1,074
star
5

zenburn-emacs

The Zenburn colour theme ported to Emacs
Emacs Lisp
951
star
6

solarized-emacs

The Solarized colour theme, ported to Emacs.
Emacs Lisp
739
star
7

helm-projectile

Helm UI for Projectile
Emacs Lisp
322
star
8

super-save

Save Emacs buffers when they lose focus
Emacs Lisp
273
star
9

powerpack

Some useful extensions to the core Ruby classes
Ruby
270
star
10

emacs.d

My personal Emacs configuration
Emacs Lisp
204
star
11

persp-projectile

Projectile integration for perspective.el
Emacs Lisp
110
star
12

guru-mode

Learn to use Emacs the way it was meant to be used (the Emacs guru way)
Emacs Lisp
100
star
13

emacs-dev-kit

An advanced self-contained Emacs configuration suitable for many software developers (deprecated)
Emacs Lisp
95
star
14

beamer-torino-theme

Torino, a pretty theme for LaTex Beamer
Emacs Lisp
38
star
15

lein-annotations

Display comment annotations in your project
Clojure
12
star
16

emacsredux

Emacs Redux is a blog dedicated to the One True Editor
HTML
11
star
17

cv

My professional CV in LaTeX
TeX
10
star
18

cl-99-problems

Solutions to the 99 Lisp problems in Common Lisp
Common Lisp
10
star
19

activerecord-extra-validators

Some nice additional validators for ActiveRecord
Ruby
9
star
20

java-in-action-lectures

The lectures from the "Java in Action" programming course
9
star
21

advent-of-code2021

Advent of Code 2021, Clojure Edition
Clojure
8
star
22

legacy-octopress-blog

My personal blog
HTML
8
star
23

batsov.com

My personal blog
Ruby
7
star
24

metaredux

HTML
7
star
25

master-thesis

My Master university degree thesis
Emacs Lisp
5
star
26

zshrc

My personal zsh setup
5
star
27

docs.projectile.mx

Projectile's documentation site
Handlebars
4
star
28

hard-cider

A demo projecto to showcase CIDER
Clojure
3
star
29

blog

My personal blog
Ruby
2
star
30

presentations

Presentations I created for various occasions
2
star
31

emacsredux-legacy

Emacs Redux
HTML
1
star
32

praxis

Praxis makes perfect!
OCaml
1
star