FG42/nix/modules/editor/lisp/fg42/editor.el

306 lines
8.6 KiB
EmacsLisp

;;; FG42 --- The mighty editor for the emacsians -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2024 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://devheroes.codes/FG42/FG42
;; Version: 4.0.0
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;; Code:
(eval-when-compile
(require 'fpkg)
;; We build this file via the main FG42's Nix derivation. It
;; contains the final Nix configuration of FG42.
(require 'fg42/config))
(require 'server)
(require 'fg42/utils)
(defun fg42/setup-font ()
"Set the default font of `FG42' to FONT-NAME and FONT-SIZE."
(let ((name (config-get font-name))
(size (config-get font-size)))
(add-to-list 'default-frame-alist
(cons 'font (format "%s-%d" name size)))
(set-face-attribute 'default t :font name)))
(use! origami
"A text folding minor mode for Emacs."
:bind
(("C-c TAB" . origami-toggle-node))
:config
(global-origami-mode t))
(use! rg
"A ripgrep based search utility."
:commands rg-menu
:bind
("C-c s" . rg-menu)
("C-c p s" . rg-dwim-project-dir))
(use! pkg-info
"`pkg-info' integration.")
(use! expand-region
"Expand region increases the selected region by semantic units.
Just keep pressing the key until it selects what you want."
:bind ("C-=" . er/expand-region))
(use! helpful
"Helpful is an alternative to the built-in Emacs help that provides much more
contextual information."
:bind
(("C-h f" . helpful-callable)
("C-h v" . helpful-variable)
("C-h k" . helpful-key)
("C-h x" . helpful-command)
("C-c C-d" . helpful-at-point)))
(use! envrc
"Activate direnv whenever encounter a `.envrc' file"
:config
(envrc-global-mode))
(use! pinentry
"Pinentry cube with setup the =pinentry= program to be used within FG42."
:commands pinentry-start
:init
(setq epa-pinentry-mode 'loopback))
(use! imenu-list
"his Emacs minor-mode creates an automatically updated buffer
called `Ilist' that is populated with the current buffer's imenu entries.
The `Ilist' buffer is typically shown as a sidebar (Emacs vertically splits the window)."
:bind (("C-'" . imenu-list-smart-toggle)))
(use! discover
"Adds support for the discover.el `https://github.com/mickeynp/discover.el'.")
(use! exec-path-from-shell
"This package fixes the =exec-path-from-shell= issue on MacOS."
:config
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize)))
(use! hl-line
"Highlights the current line."
:hook (emacs-startup . global-hl-line-mode))
(use! avy
"This cube controls the different aspect of buffer navigation"
:bind ("C-c g" . avy-goto-word-1))
(use! ace-window
"This cube controls the different aspect of buffer navigation"
:bind ("C-<tab>" . ace-window))
(when-not-wm
(use! flyspell
"Spell checking on the fly"
:commands (flyspell-mode flyspell-prog-mode)
:init
(setq-default ispell-program-name "aspell")
(setq-default ispell-extra-args '("--sug-mode=ultra"
"--lang=en_US"
"--camel-case")))
(use! savehist
"Persist history over Emacs restarts. Vertico sorts by history position."
:init
(savehist-mode))
(use! display-line-numbers
"The builtin replacement of linum. It's is pretty fast."
:config
(global-display-line-numbers-mode 1)))
(use! flycheck
"Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs."
:config (global-flycheck-mode))
(use! rainbow-delimiters
"It is a rainbow parentheses like mode which highlights delimiters such as
parentheses, brackets or braces according to their depth."
;; Enable rainbow-delimiters for programming
:hook (prog-mode . rainbow-delimiters-mode))
(use! direnv
"Direnv integration for FG42."
:config
(direnv-mode))
(use! tempel
"Tempel is a tiny template package for Emacs, which uses the syntax
of the Emacs Tempo library."
:bind (("M-=" . tempel-complete) ;; Alternative tempel-expand
("M-*" . tempel-insert)
("C-," . tempel-previous)
("C-." . tempel-next))
:init
;; Setup completion at point
(defun tempel-setup-capf ()
;; Add the Tempel Capf to `completion-at-point-functions'.
;; `tempel-expand' only triggers on exact matches. Alternatively use
;; `tempel-complete' if you want to see all matches, but then you
;; should also configure `tempel-trigger-prefix', such that Tempel
;; does not trigger too often when you don't expect it. NOTE: We add
;; `tempel-expand' *before* the main programming mode Capf, such
;; that it will be tried first.
(setq-local completion-at-point-functions
(cons #'tempel-expand
completion-at-point-functions)))
(add-hook 'conf-mode-hook 'tempel-setup-capf)
(add-hook 'prog-mode-hook 'tempel-setup-capf)
(add-hook 'text-mode-hook 'tempel-setup-capf))
(use! tempel-collection
"A collection of tempel templates.")
(use! hydra
"Once you summon the Hydra through the prefixed binding (the
body+ any one head), all heads can be called in succession with only a
short extension."
:init
(require 'hydra)
:hook (emacs-startup . hydra-add-imenu)
:config
(defhydra hydra-zoom (global-map "<f2>")
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out")))
(use! beacon
"Never lose sight of your curser."
:hook (emacs-startup . beacon-mode))
(defun fg42/setup-editor ()
"Setup the overall functionality of FG42."
;; In the following section we're setting some default behavior of FG42.
;; Most of these configuration are opiniated and I think most of people
;; shared the same opinion or don't care at all.
(fg42/setup-font)
(add-hook 'fg42/after-init-hook
(lambda ()
(set-default 'cursor-type 'bar)
(set-cursor-color "#eeeeec")))
;; Remove splash screen
(setq inhibit-splash-screen t)
;; scratch should be scratch
(setq initial-scratch-message nil)
;; Don't allow tab as indent
(setq-default indent-tabs-mode nil)
;; Default indent width
(setq tab-width 2)
;; Share the clipboard with X applications
(setq x-select-enable-clipboard t)
;; Automatically removed excess backups of the file
(setq delete-old-versions t)
;; Emacs 28 and newer: Hide commands in M-x which do not work in the current
;; mode. Vertico commands are hidden in normal buffers. This setting is
;; useful beyond Vertico.
(setq read-extended-command-predicate #'command-completion-default-include-p)
;; Support opening new minibuffers from inside existing minibuffers.
(setq enable-recursive-minibuffers t)
(setq tooltip-use-echo-area t)
(setq x-gtk-use-system-tooltips nil)
;; Emacs 30 and newer: Disable Ispell completion function.
(setq text-mode-ispell-word-completion nil)
;; Enable indentation+completion using the TAB key.
;; `completion-at-point' is often bound to M-TAB.
(setq tab-always-indent 'complete)
;; Global configurations
(tool-bar-mode -1)
(tooltip-mode nil)
(menu-bar-mode -1)
(when (display-graphic-p)
;; Smoother scrolling
(pixel-scroll-precision-mode)
(scroll-bar-mode -1))
(defalias 'yes-or-no-p 'y-or-n-p)
(set-mouse-color (get-base16-color-or :base07 "#eeeeec"))
;; Switch from `dabbrev-expand' to `hippie-expand'
(global-set-key [remap dabbrev-expand] 'hippie-expand)
(column-number-mode t)
(show-paren-mode t)
(electric-pair-mode 1)
;; Rectangular select
(cua-selection-mode t)
;; Yank the region on type
(delete-selection-mode 1)
;; Deletel extra trailing white spaces on save
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; With this section we will have two emacs server running
;; this way we can interact with the wm via emacsclient as well
(when (not (server-running-p))
(when-wm
(setq server-name "fg42-wm"))
(server-start))
(when-wm
;; Activating the WM mode
(exwm-enable)
(exwm-systemtray-enable)
(exwm-randr-enable))
(message "[FG42]: Use `fg42-help' to get help."))
(add-hook 'fg42/after-user-config-init-hook #'fg42/setup-editor)
(provide 'fg42/editor)
;;; editor.el ends here