refactoring code

This commit is contained in:
Jesus E 2023-05-12 23:08:14 -04:00
parent 4177899f78
commit df9488c745
No known key found for this signature in database
GPG Key ID: 159C8F8BC9AED8B6
7 changed files with 106 additions and 81 deletions

140
init.el
View File

@ -1,60 +1,114 @@
;;; init.el --- .Emacs Configuration -*- lexical-binding: t -*-
;;; Commentary:
;;
;; Emacs!!! ;; Emacs!!!
(package-initialize) ;;; Code:
;; Without this comment emacs25 adds (package-initialize) here
;; (package-initialize)
(when (version<= emacs-version "24") ;;; Time Mark
(error "This is made form Emacs >=24")) (setq emacs-load-start-time (current-time))
(defconst emacs-start-time (current-time)) (setq package-check-signature 'allow-unsigned)
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/" user-emacs-directory))
;;; Raise garbage collection threshold after init ;;; Fix TLS emacs 26.x
(add-hook 'after-init-hook (if (version<= emacs-version "26.2")
(lambda () (setq gc-cons-threshold local/gc-cons-threshold))) (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
;;; Custom variables ;;; Welcome message
(setq custom-file (expand-file-name "custom.el" user-emacs-directory)) (setq-default initial-scratch-message
;;; Custom settings (concat ";; Happy hacking, " user-login-name " - Emacs loves you!\n\n"))
(setq settings-file (expand-file-name "settings.el" user-emacs-directory))
(defvar before-user-init-time (current-time)
"Value of `current-time' when Emacs begins loading `user-init-file'.")
;;; Garbage Collector
(progn
;; Set this to true to find GC issues.
(setq garbage-collection-messages nil)
;; Increase the gc-cons-threshold to a very high number to decrease
;; the load and compile time. The value will be decreased
;; significantly after initialization to avoid long GC pauses during
;; normal usage.
(setq gc-cons-threshold 402653184
gc-cons-percentage 0.6)
(setq read-process-output-max (* 1024 1024)) ;; 1mb
;; Reset GC to normal values.
(add-hook 'emacs-startup-hook
(lambda ()
(message
"[STARTUP] Loading %s...done (%.3fs)" user-init-file
(float-time (time-subtract (current-time)
before-user-init-time)))
(when init-file-debug
(message "Rolling back GC settings to sane values."))
(setq gc-cons-threshold 16777216
gc-cons-percentage 0.1))))
;;; Modules directory
(push (concat user-emacs-directory "lisp") load-path)
;;; Loads settings file
(when (file-exists-p custom-file)
(load settings-file))
;;;------------------------------ ;;;------------------------------
;;; Features ;;; Features
;;;------------------------------ ;;;------------------------------
(require 'init-security) ;;; https://stackoverflow.com/questions/2816019/in-lisp-avoid-cannot-open-load-file-when-using-require
(require 'init-elpa)
;; theme
(require 'init-theme)
;; Utils
(require 'init-utils)
;; GUI
(require 'init-nlinum)
(require 'init-gui)
(require 'init-editing-utils)
(require 'init-modeline)
(require 'init-indent-guides)
;; Tools
(require 'init-flycheck)
;; Languages
(require 'init-markdown)
(require 'init-python)
(require 'init-pkgbuild)
(require 'init-php)
(require 'init-less)
(require 'init-sass)
(require 'init-scss)
;; Plus
(require 'init-rainbow)
;; @see https://www.reddit.com/r/emacs/comments/3kqt6e/2_easy_little_known_steps_to_speed_up_emacs_start/
;; Normally file-name-handler-alist is set to
;; (("\\`/[^/]*\\'" . tramp-completion-file-name-handler)
;; ("\\`/[^/|:][^/|]*:" . tramp-file-name-handler)
;; ("\\`/:" . file-name-non-special))
;; Which means on every .el and .elc file loaded during start up, it has to runs those regexps against the filename.
(let* ((file-name-handler-alist nil))
;; package-initialize' takes 35% of startup time
;; need check https://github.com/hlissner/doom-emacs/wiki/FAQ#how-is-dooms-startup-so-fast for solution
(require 'init-security)
(require 'init-elpa)
;; theme
(require 'init-theme)
;; Utils
(require 'init-utils)
;; GUI
(require 'init-nlinum)
(require 'init-gui)
(require 'init-editing-utils)
(require 'init-modeline)
(require 'init-indent-guides)
;; Tools
(require 'init-flycheck)
;; Languages
(require 'init-markdown)
(require 'init-python)
(require 'init-pkgbuild)
(require 'init-php)
(require 'init-less)
(require 'init-sass)
(require 'init-scss)
;; Plus
(require 'init-rainbow))
;;; Custom variables
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
;;; Loads custom file ;;; Loads custom file
(when (file-exists-p custom-file) (when (file-exists-p custom-file)
(load custom-file)) (load custom-file))
(when window-system ;;; Settings
(let ((elapsed (float-time (time-subtract (current-time) (setq settings-file (expand-file-name "settings.el" user-emacs-directory))
emacs-start-time)))) ;;; Loads settings file
(message "[STARTUP] Loading %s ... done (%.3fs)" load-file-name elapsed))) (when (file-exists-p custom-file)
(load settings-file))
;; enable erase-buffer command
(put 'erase-buffer 'disabled nil)
(provide 'init) (provide 'init)
;; Local Variables:
;; byte-compile-warnings: (not free-vars)
;; End:
;;; init.el ends here

View File

@ -32,5 +32,4 @@
(setq-default (setq-default
indent-tabs-mode nil) indent-tabs-mode nil)
(myemacs/elapsed-time)
(provide 'init-editing-utils) (provide 'init-editing-utils)

View File

@ -12,23 +12,18 @@
;; Repositories ;; Repositories
;; ================ ;; ================
(setq package-archives (setq package-archives
'(("melpa" . "https://melpa.org/packages/") '(("GNU ELPA" . "https://elpa.gnu.org/packages/")
;;("melpa-stable" . "https://stable.melpa.org/packages/") ("MELPA Stable" . "https://stable.melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/") ("ORG" . "https://orgmode.org/elpa/")
("org" . "https://orgmode.org/elpa/"))) ("MELPA" . "https://melpa.org/packages/"))
package-archive-priorities
'(("MELPA Stable" . 10)
("GNU ELPA" . 5)
("ORG" . 3)
("MELPA" . 0)))
(setq package-archive-priorities
'(("melpa" . 4)
("melpa-stable" . 0)
("gnu" . 1)
("org" . 3)))
;; ================= ;; =================
;; Refresh packages in Emacs
;; ==========================
(when (not package-archive-contents)
(package-refresh-contents))
;;; Find packages if not installed ;;; Find packages if not installed
;; ================================ ;; ================================
;;; On-demand installation of packages ;;; On-demand installation of packages

View File

@ -42,5 +42,4 @@
(global-set-key (kbd "M-%") 'anzu-query-replace) (global-set-key (kbd "M-%") 'anzu-query-replace)
(global-set-key (kbd "s-<SPC>") 'anzu-query-replace) (global-set-key (kbd "s-<SPC>") 'anzu-query-replace)
(myemacs/elapsed-time)
(provide 'init-modeline) (provide 'init-modeline)

View File

@ -60,5 +60,4 @@
(add-hook 'php-mode-hook 'my/php-mode-stuff) (add-hook 'php-mode-hook 'my/php-mode-stuff)
(myemacs/elapsed-time)
(provide 'init-php) (provide 'init-php)

View File

@ -18,7 +18,4 @@
'(eval-after-load ,feature '(eval-after-load ,feature
'(progn ,@body)))) '(progn ,@body))))
;; Elapsed time
(myemacs/elapsed-time)
(provide 'init-utils) (provide 'init-utils)

View File

@ -1,18 +0,0 @@
;;----------------------------------------------------------------------------
;; Some cool functions
;;----------------------------------------------------------------------------
;; These functions are made by me (Quitter: @heckyel) or
;; heavily modified by me
;;----------------------------------------------------------------------------
;; Toggles fullscreen
;;----------------------------------------------------------------------------
(defun myemacs/toggle-fullscreen ()
(interactive)
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_FULLSCREEN" 0)))
(defun myemacs/elapsed-time ()
(let ((elapsed (float-time (time-subtract (current-time)
emacs-start-time))))
(message "[STARTUP] Loading %s ... done (%.3fs)" load-file-name elapsed)))