FG42/lisp/fg42/cubes/editor.el

378 lines
11 KiB
EmacsLisp

;;; EditorCubes --- The common cubes for FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2023 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://devheroes.codes/FG42/FG42
;; Version: 3.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:
(require 'server)
(require 'fpkg)
(require 'fg42/cube)
(require 'fg42/utils)
(require 'fg42/modeline)
(require 'fg42/cubes/modeline)
(require 'fg42/themes)
(require 'fg42/project)
(defflag font-icons
"Enable the support for font icones in FG42." t)
(defflag server
"Enable the support for server mode in FG42." t)
(defcube fg42/folding-cube
"This cube install ~origami~ which let you collapse and expand regions of text.
For more info checkout [[https://github.com/gregsexton/origami.el]]"
:title "Folding cube"
:flag folding
:flag-default t
(fpkg/use origami
:bind
(("C-c TAB" . origami-toggle-node))
:config
(global-origami-mode t)))
(->cube dirvish
"Dirvish is an improved version of the Emacs inbuilt package Dired.
It not only gives Dired an appealing and highly customizable user interface,
but also comes together with almost all possible parts required for full usability
as a modern file manager."
:init
(dirvish-override-dired-mode))
(->cube which-key
"which-key is a minor mode for Emacs that displays the key bindings following
your currently entered incomplete command (a prefix) in a popup. For example,
after enabling the minor mode if you enter ~C-x~ and wait for the default of
1 second the minibuffer will expand with all of the available key bindings
that follow ~C-x~ (or as many as space allows given your settings).
This includes prefixes like ~C-x 8~ which are shown in a different face."
:init
(require 'which-key)
:config
(which-key-setup-side-window-bottom)
(which-key-mode))
(->cube helpful
"Helpful is an alternative to the built-in Emacs help that provides much more
contextual information."
:init
(require 'helpful)
:config
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
(global-set-key (kbd "C-h x") #'helpful-command)
(global-set-key (kbd "C-c C-d") #'helpful-at-point))
(defcube fg42/pinentry-cube
"Pinentry cube with setup the =pinentry= program to be used within FG42."
:title "Pinentry cube"
:flag pinentry
:flag-default t
(fpkg/use pinentry
:init
(progn
(setq epa-pinentry-mode 'loopback)
(pinentry-start))))
(defcube fg42/imenu-cube
"Imenu support"
:title "Imenu cube"
:flag imenu
:flag-default t
(fpkg/use imenu-list
:init
(global-set-key (kbd "C-'") #'imenu-list-smart-toggle)))
(defcube fg42/alert-cube
"alert support"
:title "Alert cube"
:flag alert
:flag-default t
(fpkg/use alert))
(defcube fg42/emojify-cube
"Adds support for emojis to *FG42*"
:title "Emojify cube"
:flag emoji
:flag-default t
(fpkg/use emojify
:hook (after-init . global-emojify-mode)))
(defcube fg42/discover-cube
"Adds support for the [[https://github.com/mickeynp/discover.el][discover]]"
:title "Discover cube"
:flag discover
:flag-default t
(fpkg/use discover))
(defcube fg42/exec-path-cube
"This cube fixes the =exec-path-from-shell= issue on MacOS."
:title "Exec path cube"
:flag exec-path-from-shell
:flag-default t
(fpkg/use exec-path-from-shell
:init
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))))
(defcube fg42/hl-cube
"This cube highlight the curret line."
:title "Current line highlight cube"
:flag hl-line
:flag-default t
(require 'hl-line)
(global-hl-line-mode))
(defcube fg42/rainbow-delimiters-cube
"rainbow-delimiters is a =rainbow parentheses= like mode which highlights delimiters
such as parentheses, brackets or braces according to their depth. Each successive level
is highlighted in a different color. This makes it easy to spot matching delimiters,
orient yourself in the code, and tell which statements are at a given depth."
:title "Rainbow Delimiters Cube"
:flag rainbow-delimiters
:flag-default t
(fpkg/use rainbow-delimiters
;; It doesn't work due to a problem/conflict in rainbow-delimiters
;; But we use it any way they might fix it
:hook (prog-mode . rainbow-delimiters-mode)))
(defcube fg42/paredit-cube
"=paredit= is a minor mode for performing structured editing of S-expression
data. The typical example of this would be Lisp or Scheme source code."
:title "Paredit Cube"
:flag paredit
:flag-default t
(fpkg/use paredit
:hook ((emacs-lisp-mode . paredit-mode)
(clojure-mode . paredit-mode)
(scheme-mode . paredit-mode))))
(defcube fg42/cursor-cube
"This cube controls the shape of the cursor."
:title "Cursor cube"
:flag cursor-type
:flag-default t
(let ((ctype (or (plist-get fg42/cursor-cube-params :type) 'box))
(ccolor (or (plist-get fg42/cursor-cube-params :color) "#aa0000")))
(add-hook 'fg42/after-initializing-theme-hook
(lambda ()
(set-default 'cursor-type ctype)
(set-cursor-color ccolor)))))
(defcube fg42/buffer-navigation-cube
"This cube controls the different aspect of buffer navigation"
:title "Buffer navigation cube"
:flag buffer-navigation
:flag-default t
(fpkg/use avy
:bind ("M-1" . avy-goto-word-1)))
(defcube fg42/window-navigation-cube
"This cube controls the different aspect of buffer navigation"
:title "Window navigation cube"
:flag window-navigation
:flag-default t
(fpkg/use ace-window
:bind ("C-<tab>" . ace-window)))
(defcube fg42/font-cube
"This cube controls the font configuration of *FG42*"
:title "Font Cube"
:no-flag t
:flag-default t
(let ((font (or (plist-get fg42/font-cube-params :font-name)
"Fira Mono"))
(size (or (plist-get fg42/font-cube-params :font-size)
12)))
(when font
;; Sets the default font to fg42 font
(add-to-list 'default-frame-alist
(cons 'font (format "%s-%d" font size)))
(set-face-attribute 'default t :font font))))
;; ;TODO: Replace this cube with a `theme-cube'
;; (defcube fg42/dracula-theme-cube
;; "Replace this with a theme cube"
;; :title "Dracula theme"
;; :no-flag t
;; :ui-hook (lambda ()
;; (fpkg/use dracula-theme
;; :init
;; (fg42/setup-theme
;; (load-theme 'dracula t)
;; (custom-theme-set-faces
;; 'dracula
;; '(match ((t (:background "#44475a"))))
;; '(all-the-icons-lgreen ((t (:background "#bd93f9"))))
;; '(all-the-icons-faicon ((t (:background "#bd93f9"))))
;; '(font-lock-comment-face ((t (:foreground "#8B9298"))))
;; '(font-lock-comment-delimiter-face ((t (:foreground "#5B6268")))))
;; (enable-theme 'dracula)
;; (set-face-attribute 'region nil :background "#888")))))
(defcube fg42/badwolf-theme-cube
"Badwolf theme cube. An Emacs port of Bad Wolf theme for Vim.
https://emacsthemes.com/themes/badwolf-theme.html"
:title "Badwolf theme"
:no-flag t
(require 'fg42/themes)
(fpkg/use badwolf-theme
:init
(fg42/setup-theme
(load-theme 'badwolf t)
(custom-theme-set-faces
'badwolf)
(enable-theme 'badwolf))))
(defcube fg42/selectrum-cube
"This cube adds support for `selectrum' to FG42"
:title "Selectrum cube"
:flag selectrum
:flag-default t
(fpkg/use selectrum
:defer nil
:init
(selectrum-mode +1))
(fpkg/use selectrum-prescient
:defer t
:init
(progn
(setq prescient-filter-method '(literal fuzzy regexp initialism))
(selectrum-prescient-mode +1)
(prescient-persist-mode +1)))
;; TODO: Disbale ctrlf in WM mode
(fpkg/use ctrlf
:defer t
:init
(ctrlf-mode +1)))
(defcube fg42/editor-cube
"This is a meta cube that sets up the basic functionalities of an Editor"
:title "Editor cube"
:no-flag t
(fg42/disable-modeline-cube)
(fpkg/use rainbow-delimiters
;; It doesn't work due to a problem/conflict in rainbow-delimiters
;; But we use it any way they might fix it
:hook (prog-mode . rainbow-delimiters-mode))
(when-flag font-icon
(fpkg/use all-the-icons))
;; 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.
;; 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)
;; Global configurations
(tool-bar-mode -1)
(menu-bar-mode -1)
(when (display-graphic-p)
(scroll-bar-mode -1))
(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)
(defalias 'yes-or-no-p 'y-or-n-p)
;; Hooks ---
;; Deletel extra trailing white spaces on save
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Enable rainbow-delimiters for programming
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
(when-flag server
(when (not (server-running-p))
(when-wm
(setq server-name "fg42-wm"))
(server-start)))
;; Call the editor related cubes. They will be run only if
;; their flag is active otherwise they will be skipped
(when-flag fg42-project
(fg42-project-global-mode t))
(let ((mline (or (plist-get fg42/editor-cube-params :modeline)
#'fg42/default-modeline)))
;;(fg42/statusbar-cube)
;;(fg42/modeline-cube)
;; (fg42/setup-modeline-format mline)
))
(provide 'fg42/cubes/editor)
;;; editor.el ends here