FG42/core/cubes/editor.el

281 lines
7.5 KiB
EmacsLisp

;;; EditorCubes --- The common cubes for FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2022 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://gitlab.com/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 'cubes/modeline)
(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)))
(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/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/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)
(require 'fg42/themes)
(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))))
(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)
(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)
(scroll-bar-mode -1)
(menu-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
(let ((mline (or (plist-get fg42/editor-cube-params :modeline)
#'fg42/default-modeline)))
;;(fg42/statusbar-cube)
(fg42/modeline-cube)
(fg42/setup-modeline-format mline))
(fg42/folding-cube)
(fg42/font-cube)
(fg42/pinentry-cube)
(fg42/exec-path-cube)
(fg42/buffer-navigation-cube)
(fg42/window-navigation-cube)
(fg42/selectrum-cube)
(fg42/cursor-cube)
(fg42/hl-cube))
(provide 'cubes/editor)
;;; editor.el ends here