config.phundrak.com/docs/emacs/packages/editing.org
Lucien Cartier-Tilet 788ecefbe5
docs(emacs): move most keybindings to same file
All general keybindings (not linked to a specific mode) are now
defined in keybindings.org in neatly displayed tables.
2024-04-03 06:07:58 +02:00

5.6 KiB
Raw Permalink Blame History

Emacs — Packages — Editing

Editing

First, Ill define some keybindings for easily inserting pairs when editing text.

(general-define-key
 :states 'visual
 "M-["  #'insert-pair
 "M-{"  #'insert-pair
 "M-<"  #'insert-pair
 "M-'"  #'insert-pair
 "M-`"  #'insert-pair
 "M-\"" #'insert-pair)

Atomic Chrome

Why write in your browser when you could write with Emacs? Despite its name, this package isnt only geared towards Chrome/Chromium-based browsers but also towards Firefox since its 2.0 version. I find it a bit unfortunate Chromes name stuck in the packages name though.

(use-package atomic-chrome
  :straight (:build t)
  :init
  (atomic-chrome-start-server)
  :config
  (setq atomic-chrome-default-major-mode 'markdown-mode
        atomic-chrome-url-major-mode-alist `(("github\\.com"          . gfm-mode)
                                             ("gitlab\\.com"          . gfm-mode)
                                             ("labs\\.phundrak\\.com" . markdown-mode)
                                             ("reddit\\.com"          . markdown-mode))))

Editorconfig

Editorconfig is a unified way of passing to your text editor settings everyone working in a repo need to follow. .editorconfig files work for VSCode users, vim users, Atom users, Sublime users, and of course Emacs users.

(use-package editorconfig
  :defer t
  :straight (:build t)
  :diminish editorconfig-mode
  :init
  (editorconfig-mode t))

Evil Nerd Commenter

Emacs default commenting system is nice, but I dont find it smart enough for me.

(use-package evil-nerd-commenter
  :after evil
  :straight (:build t))

Iedit

Iedit is a powerful text editing tool that can be used to refactor code through the edition of multiple regions at once, be it in a region or in a whole buffer. Since Im using evil, Ill also use a compatibility package that adds states for iedit.

(use-package evil-iedit-state
  :defer t
  :straight (:build t)
  :commands (evil-iedit-state evil-iedit-state/iedit-mode)
  :init
  (setq iedit-curent-symbol-default     t
        iedit-only-at-symbol-boundaries t
        iedit-toggle-key-default        nil)
  :general
  (general-define-key
   :keymaps 'evil-iedit-state-map
   "c" nil
   "s" nil
   "J" nil
   "S" #'iedit-expand-down-a-line
   "T" #'iedit-expand-up-a-line
   "h" #'evil-iedit-state/evil-change
   "k" #'evil-iedit-state/evil-substitute
   "K" #'evil-iedit-state/substitute
   "q" #'evil-iedit-state/quit-iedit-mode))

Smartparens

(use-package smartparens
  :straight (:build t)
  :defer t)

Parinfer

Dont let the name of the package fool you! parinfer-rust-mode is not a parinfer mode for rust-mode, but a mode for parinfer-rust. parinfer was a project for handling parenthesis and other double markers in a much more intuitive way when writing Lisp code. However, it is now out of date (last commit was on January 2nd, 2019) and the repository has since been archived. New implementations then appeared, one of them is parinfer-rust, obviously written in Rust, around which parinfer-rust-mode is built. Enabling parinfer-rust-mode should also automatically disable smartparens-mode in order to avoid conflicting behavior.

(use-package parinfer-rust-mode
  :defer t
  :straight (:build t)
  :diminish parinfer-rust-mode
  :hook emacs-lisp-mode common-lisp-mode scheme-mode
  :init
  (setq parinfer-rust-auto-download     t
        parinfer-rust-library-directory (concat user-emacs-directory
                                                "parinfer-rust/"))
  (add-hook 'parinfer-rust-mode-hook
            (lambda () (smartparens-mode -1)))
  :general
  (phundrak/major-leader-key
    :keymaps 'parinfer-rust-mode-map
    "m" #'parinfer-rust-switch-mode
    "M" #'parinfer-rust-toggle-disable))

Smartparens

smartparens is a package similar to parinfer, but while the latter is more specialized for Lisp dialects, smartparens works better with other programming languages that still uses parenthesis, but not as much as Lisp dialects; think for example C, C++, Rust, JavaScript, and so on.

(use-package smartparens
  :defer t
  :straight (smartparens :build t
                         :type git
                         :host github
                         :repo "Fuco1/smartparens")
  :hook (prog-mode . smartparens-mode))

string-edit

string-edit is a cool package that allows the user to write naturally a string and get it automatically escaped for you. No more manually escaping your strings!

(use-package string-edit-at-point
  :defer t
  :straight (:build t))

Writeroom

On the other hand, writeroom allows the user to enter a distraction-free mode of Emacs, and I like that! But the default width is a bit too small for me, and I prefer not to go full-screen.

(use-package writeroom-mode
  :defer t
  :straight (:build t)
  :init (global-writeroom-mode 1)
  :config
  (setq writeroom-width             100
        writeroom-fullscreen-effect nil
        writeroom-maximize-window   nil
        writeroom-mode-line         t
        writeroom-major-modes       '(text-mode org-mode markdown-mode nov-mode Info-mode)))