add configuration

This commit is contained in:
Rawley Fowler
2023-08-07 20:32:58 -06:00
commit 2d712e3c63
3 changed files with 671 additions and 0 deletions

251
extras/extras/perltidy.el Normal file
View File

@@ -0,0 +1,251 @@
;;; perltidy.el --- Tidy perl code
;; Copyright (C) 2007-2015 Free Software Foundation, Inc.
;;
;; Author: Ye Wenbin <wenbinye@gmail.com>
;; Maintainer: Kirill Babikhin <mrakobes86reg@yandex.ru>
;; Created: 22 Dec 2007
;; Version: 0.05
;; Keywords: tools, convenience, languages
;; 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 2, 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, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;; Commentary:
;; As the PBP(Perl Best Practice) suggest, put this to your ~/.perltidyrc:
;; ## .perltidyrc --- configuration for perltidy
;; # Max line width is 78 cols
;; -l=78
;; # Indent level is 4 cols
;; -i=4
;; # Continuation indent is 4 cols
;; -ci=4
;; # Output to STDOUT
;; -st
;; # Errors to STDERR
;; -se
;; # Maximal vertical tightness
;; -vt=2
;; # No extra indentation for closing brackets
;; -cti=0
;; # Medium parenthesis tightness
;; -pt=1
;; # Medium brace tightness
;; -bt=1
;; # Medium square bracket tightness
;; -sbt=1
;; # Medium block brace tightness
;; -bbt=1
;; # No space before semicolons
;; -nsfs
;; # Don't outdent long quoted strings
;; -nolq
;; # Break before all operators
;; -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
;; Put this file into your load-path and the following into your ~/.emacs:
;; (require 'perltidy)
;;; Code:
(eval-when-compile
(require 'cl))
(defgroup perltidy nil
"Tidy perl code using perltidy"
:group 'tools
:group 'pde)
(defcustom perltidy-program "perltidy"
"*Program name of perltidy"
:type 'string
:group 'perltidy)
(defcustom perltidy-program-params
'(;; I/O control
"--standard-output"
"--standard-error-output"
"--force-read-binary"
"--quiet"
;; FORMATTING OPTIONS
"--no-check-syntax"
)
"*perltidy run options"
:type 'list
:group 'perltidy)
(defcustom perltidy-rcregex "\\.perltidyrc"
"perltidyrc file regex"
:type 'string
:group 'perltidy)
(defmacro perltidy-save-point (&rest body)
(declare (indent 0) (debug t))
`(let ((old-point (point)))
,@body
(goto-char old-point)))
;;;###autoload
(defun perltidy-region (beg end)
"Tidy perl code in the region."
(interactive "r")
(or (get 'perltidy-program 'has-perltidy)
(if (executable-find perltidy-program)
(put 'perltidy-program 'has-perltidy t)
(error "Seem perltidy is not installed")))
(perltidy-save-point
(let ((old-perltidy-env (getenv "PERLTIDY"))
(remote? (tramp-tramp-file-p buffer-file-name))
(perltidyrc (perltidy-find-perltidyrc buffer-file-truename))
(perltidyrc-remote (expand-file-name "perltidyrc-remote" temporary-file-directory))
(perltidy-run-list perltidy-program-params)
)
(if (and (bound-and-true-p remote?)
perltidyrc)
(progn
(require 'tramp-sh)
(tramp-sh-handle-copy-file perltidyrc perltidyrc-remote t)
(setq perltidyrc perltidyrc-remote)))
(if perltidyrc
(setq perltidy-run-list
(append perltidy-run-list
(list (concat "-pro=" perltidyrc)))))
(apply #'call-process-region
(append (list beg end perltidy-program
t
t
t
)
perltidy-run-list)))
t))
;;;###autoload
(defun perltidy-buffer ()
"Call perltidy for whole buffer."
(interactive)
(perltidy-region (point-min) (point-max)))
;;;###autoload
(defun perltidy-subroutine ()
"Call perltidy for subroutine at point."
(interactive)
(save-excursion
(let ((current-point (point))
b e)
(setq b (progn (beginning-of-defun) (point)))
(when (and
(looking-at "\\s-*sub\\s-+")
(< b current-point)
(> (save-excursion
(setq e (progn (end-of-defun) (point))))
current-point))
(perltidy-region b e)))))
;;;###autoload
(defun perltidy-dwim-safe (arg)
"Perltidy Do What I Mean safe.
If region is active call perltidy on the region.
If inside subroutine, call perltidy on the subroutine,
otherwise stop."
(interactive "P")
(let ((buf (current-buffer))
beg end)
(cond ((and mark-active transient-mark-mode)
(setq beg (region-beginning)
end (region-end)))
((save-excursion
(let ((current-point (point))
b e)
(setq b (progn (beginning-of-defun) (point)))
(when (and
(looking-at "\\s-*sub\\s-+")
(< b current-point)
(> (save-excursion
(setq e (progn (end-of-defun) (point))))
current-point))
(setq beg b
end e)))))
(t (setq beg nil
end nil)))
(if (and beg
end)
(progn
(perltidy-region beg end)
(font-lock-fontify-buffer)))))
;;;###autoload
(defun perltidy-dwim (arg)
"Perltidy Do What I Mean.
If region is active call perltidy on the region.
If inside subroutine, call perltidy on the subroutine,
otherwise call perltidy for whole buffer."
(interactive "P")
(let ((buf (current-buffer))
beg end)
(cond ((and mark-active transient-mark-mode)
(setq beg (region-beginning)
end (region-end)))
((save-excursion
(let ((current-point (point))
b e)
(setq b (progn (beginning-of-defun) (point)))
(when (and
(looking-at "\\s-*sub\\s-+")
(< b current-point)
(> (save-excursion
(setq e (progn (end-of-defun) (point))))
current-point))
(setq beg b
end e)))))
(t (setq beg (point-min)
end (point-max))))
(perltidy-region beg end)
(font-lock-fontify-buffer)))
(defun perltidy-find-perltidyrc (&optional dir rcregex)
(unless dir (setq dir (buffer-file-name)))
(unless rcregex (setq rcregex perltidy-rcregex))
(setq dir (file-name-directory dir))
(let (rcfile)
(catch 'my-tag
(locate-dominating-file
dir
(lambda (parent)
(let ((rc (car (ignore-errors (directory-files parent t rcregex))))
(pparent (file-name-directory (directory-file-name parent))))
(setq rcfile rc)
(cond ((equal parent
pparent)
(if (= (length rc) 0)
(throw 'my-tag rc)
(throw 'my-tag nil)))
((and (= (length rc) 0)
(file-exists-p (expand-file-name "lib" pparent))
(file-directory-p (expand-file-name "lib" pparent)))
(setq rcfile (car (ignore-errors (directory-files pparent t rcregex))))
(throw 'my-tag rcfile))
(t rc))))))
rcfile))
(provide 'perltidy)
;;; perltidy.el ends here

241
extras/perltidy.el Normal file
View File

@@ -0,0 +1,241 @@
;;; perltidy.el --- Tidy perl code
;; Copyright (C) 2007-2015 Free Software Foundation, Inc.
;;
;; Author: Ye Wenbin <wenbinye@gmail.com>
;; Maintainer: Kirill Babikhin <mrakobes86reg@yandex.ru>
;; Created: 22 Dec 2007
;; Version: 0.05
;; Keywords: tools, convenience, languages
;; 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 2, 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, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;; Commentary:
;; As the PBP(Perl Best Practice) suggest, put this to your ~/.perltidyrc:
;; ## .perltidyrc --- configuration for perltidy
;; # Max line width is 78 cols
;; -l=78
;; # Indent level is 4 cols
;; -i=4
;; # Continuation indent is 4 cols
;; -ci=4
;; # Output to STDOUT
;; -st
;; # Errors to STDERR
;; -se
;; # Maximal vertical tightness
;; -vt=2
;; # No extra indentation for closing brackets
;; -cti=0
;; # Medium parenthesis tightness
;; -pt=1
;; # Medium brace tightness
;; -bt=1
;; # Medium square bracket tightness
;; -sbt=1
;; # Medium block brace tightness
;; -bbt=1
;; # No space before semicolons
;; -nsfs
;; # Don't outdent long quoted strings
;; -nolq
;; # Break before all operators
;; -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
;; Put this file into your load-path and the following into your ~/.emacs:
;; (require 'perltidy)
;;; Code:
(eval-when-compile
(require 'cl))
(defgroup perltidy nil
"Tidy perl code using perltidy"
:group 'tools
:group 'pde)
(defcustom perltidy-program "perltidy"
"*Program name of perltidy"
:type 'string
:group 'perltidy)
(defcustom perltidy-program-params
'(;; I/O control
"--standard-output"
"--standard-error-output"
"--force-read-binary"
"--quiet"
;; FORMATTING OPTIONS
"--no-check-syntax"
)
"*perltidy run options"
:type 'list
:group 'perltidy)
(defcustom perltidy-rcregex "\\.perltidyrc"
"perltidyrc file regex"
:type 'string
:group 'perltidy)
(defmacro perltidy-save-point (&rest body)
(declare (indent 0) (debug t))
`(let ((old-point (point)))
,@body
(goto-char old-point)))
;;;###autoload
(defun perltidy-region (beg end)
"Tidy perl code in the region."
(interactive "r")
(or (get 'perltidy-program 'has-perltidy)
(if (executable-find perltidy-program)
(put 'perltidy-program 'has-perltidy t)
(error "Seem perltidy is not installed")))
(perltidy-save-point
(let ((old-perltidy-env (getenv "PERLTIDY"))
(perltidyrc (perltidy-find-perltidyrc buffer-file-truename))
(perltidy-run-list perltidy-program-params)
)
(if perltidyrc
(setq perltidy-run-list
(append perltidy-run-list
(list (concat "-pro=" perltidyrc)))))
(apply #'call-process-region
(append (list beg end perltidy-program
t
t
t
)
perltidy-run-list)))
t))
;;;###autoload
(defun perltidy-buffer ()
"Call perltidy for whole buffer."
(interactive)
(perltidy-region (point-min) (point-max)))
;;;###autoload
(defun perltidy-subroutine ()
"Call perltidy for subroutine at point."
(interactive)
(save-excursion
(let ((current-point (point))
b e)
(setq b (progn (beginning-of-defun) (point)))
(when (and
(looking-at "\\s-*sub\\s-+")
(< b current-point)
(> (save-excursion
(setq e (progn (end-of-defun) (point))))
current-point))
(perltidy-region b e)))))
;;;###autoload
(defun perltidy-dwim-safe (arg)
"Perltidy Do What I Mean safe.
If region is active call perltidy on the region.
If inside subroutine, call perltidy on the subroutine,
otherwise stop."
(interactive "P")
(let ((buf (current-buffer))
beg end)
(cond ((and mark-active transient-mark-mode)
(setq beg (region-beginning)
end (region-end)))
((save-excursion
(let ((current-point (point))
b e)
(setq b (progn (beginning-of-defun) (point)))
(when (and
(looking-at "\\s-*sub\\s-+")
(< b current-point)
(> (save-excursion
(setq e (progn (end-of-defun) (point))))
current-point))
(setq beg b
end e)))))
(t (setq beg nil
end nil)))
(if (and beg
end)
(progn
(perltidy-region beg end)
(font-lock-fontify-buffer)))))
;;;###autoload
(defun perltidy-dwim (arg)
"Perltidy Do What I Mean.
If region is active call perltidy on the region.
If inside subroutine, call perltidy on the subroutine,
otherwise call perltidy for whole buffer."
(interactive "P")
(let ((buf (current-buffer))
beg end)
(cond ((and mark-active transient-mark-mode)
(setq beg (region-beginning)
end (region-end)))
((save-excursion
(let ((current-point (point))
b e)
(setq b (progn (beginning-of-defun) (point)))
(when (and
(looking-at "\\s-*sub\\s-+")
(< b current-point)
(> (save-excursion
(setq e (progn (end-of-defun) (point))))
current-point))
(setq beg b
end e)))))
(t (setq beg (point-min)
end (point-max))))
(perltidy-region beg end)
(font-lock-fontify-buffer)))
(defun perltidy-find-perltidyrc (&optional dir rcregex)
(unless dir (setq dir (buffer-file-name)))
(unless rcregex (setq rcregex perltidy-rcregex))
(setq dir (file-name-directory dir))
(let (rcfile)
(catch 'my-tag
(locate-dominating-file
dir
(lambda (parent)
(let ((rc (car (ignore-errors (directory-files parent t rcregex))))
(pparent (file-name-directory (directory-file-name parent))))
(setq rcfile rc)
(cond ((equal parent
pparent)
(if (= (length rc) 0)
(throw 'my-tag rc)
(throw 'my-tag nil)))
((and (= (length rc) 0)
(file-exists-p (expand-file-name "lib" pparent))
(file-directory-p (expand-file-name "lib" pparent)))
(setq rcfile (car (ignore-errors (directory-files pparent t rcregex))))
(throw 'my-tag rcfile))
(t rc))))))
rcfile))
(provide 'perltidy)
;;; perltidy.el ends here

179
init.el Normal file
View File

@@ -0,0 +1,179 @@
;;; init.el --- Perl 5 Emacs Configuration
;;; Commentary:
;;; A Perl 5 focused Emacs configuration, for the unix genie.
;;; Code:
(server-start)
;; -- Get Font Here --
;; https://github.com/slavfox/Cozette/releases
(add-to-list 'default-frame-alist '(font . "JetBrainsMono Nerd Font-16"))
(add-to-list 'default-frame-alist (list '(width . 40) '(height . 40)))
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist '(("." . "~/.saves")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
(setq package-enable-at-startup nil)
(setq visible-bell nil)
(setq ring-bell-function 'ignore)
(setq shell-file-name "/bin/bash")
(setq shell-command-switch "-ic")
(setq indent-tabs-mode nil)
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(global-linum-mode)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(menu-bar-mode -1)
(show-paren-mode 1)
(recentf-mode 1)
(defun set-exec-path-from-shell ()
"Set up Emacs' 'exec-path' and PATH environment."
(interactive)
(let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(set-exec-path-from-shell)
(add-to-list 'load-path "~/.emacs.d/extras")
;; Packages
(require 'package)
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(defconst global/pkgs
'(dracula-theme
flycheck
raku-mode
web-mode
json-mode
yaml-mode
php-mode
dockerfile-mode
ctrlf
magit
centaur-tabs
evil
smex
tree-sitter
tree-sitter-langs))
(when (not package-archive-contents)
(package-refresh-contents))
(dolist (pkg global/pkgs)
(unless (package-installed-p pkg)
(package-install pkg)))
;; General Configutations
(global-flycheck-mode)
(setq flycheck-perlcritic-severity 3)
(require 'tree-sitter)
(require 'tree-sitter-langs)
(require 'ctrlf)
(ctrlf-mode +1)
(require 'ido)
(ido-mode 1)
(require 'smex)
(smex-initialize)
(require 'centaur-tabs)
(centaur-tabs-mode t)
(global-set-key (kbd "C-<prior>") 'centaur-tabs-backward)
(global-set-key (kbd "C-<next>") 'centaur-tabs-forward)
(setq centaur-tabs-plain-icons t)
(setq centaur-tabs-set-bar 'under)
(setq x-underline-at-descent-line t)
(setq centaur-tabs-enable-key-bindings t)
(centaur-tabs-change-fonts "JetBrainsMono Nerd Font" 140)
(require 'evil)
(evil-mode 1)
(defun save-and-kill-this-buffer ()
"Save and kill buffer."
(interactive)
(save-buffer)(kill-current-buffer))
(evil-ex-define-cmd "wq" 'save-and-kill-this-buffer)
(defun kill-inner-word ()
"It's ciw from Vim."
(interactive)
(backward-word)
(kill-word 1))
;;; Language Specific Configurations
;; Perl
(require 'perltidy) ; Thanks to https://github.com/zakame/perltidy.el
(require 'perl-mode)
(require 'cperl-mode)
(setq cperl-set-style "linux")
(setq cperl-highlight-variables-indiscriminately t)
(defalias 'perl-mode 'cperl-mode)
(add-hook 'before-save-hook #'(lambda ()
(when (or (eq major-mode 'perl-mode) (eq major-mode 'cperl-mode))
(perltidy-buffer))))
(add-hook 'cperl-mode-hook #'tree-sitter-hl-mode)
(setq cperl-indent-parens-as-block t)
(eval-after-load 'cperl-mode
'(progn
(set-face-attribute 'cperl-array-face nil
:foreground 'unspecified
:background 'unspecified
:weight 'normal
:slant 'italic
)
(set-face-attribute 'cperl-hash-face nil
:foreground 'unspecified
:background 'unspecified
:weight 'normal
:slant 'italic
)
))
;; PHP
(add-to-list 'auto-mode-alist '("\\.blade.php\\'" . web-mode))
;; Keys
(global-set-key (kbd "C-c C-c") #'kill-inner-word)
(global-set-key (kbd "M-x") #'smex)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes '(dracula))
'(custom-safe-themes
'("fe1c13d75398b1c8fd7fdd1241a55c286b86c3e4ce513c4292d01383de152cb7" default))
'(delete-selection-mode nil)
'(package-selected-packages '(raku-mode docker-compose-mode flycheck dracula-theme))
'(safe-local-variable-values
'((eval let
((project-dir
(expand-file-name
(locate-dominating-file default-directory ".dir-locals.el"))))
(setq-local flycheck-perl-include-path
(list
(concat project-dir "lib")
(concat project-dir "local/lib/perl5/")))))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(provide 'init)
;;; init.el ends here.