From 31c27249448c7dcca9d1bbc8e9b21dc945098785 Mon Sep 17 00:00:00 2001 From: "Mingde (Matthew) Zeng" Date: Wed, 12 Aug 2020 21:33:24 -0400 Subject: [PATCH] simplify init-const Signed-off-by: Mingde (Matthew) Zeng --- elisp/init-company.el | 6 ++--- elisp/init-const.el | 49 +++---------------------------------- elisp/init-eaf.el | 8 +++--- elisp/init-epaint.el | 7 ++---- elisp/init-eww.el | 4 +-- elisp/init-flycheck.el | 7 ++---- elisp/init-fonts.el | 9 +++---- elisp/init-global-config.el | 11 ++++++--- elisp/init-indent.el | 7 ++---- elisp/init-input-method.el | 5 +--- elisp/init-java.el | 7 ++---- elisp/init-lsp.el | 7 ++---- elisp/init-magit.el | 12 ++++----- elisp/init-pdf.el | 4 +-- elisp/init-projectile.el | 5 ++-- elisp/init-python.el | 4 +-- elisp/init-search.el | 14 ++++++----- elisp/init-shell.el | 4 +-- 18 files changed, 59 insertions(+), 111 deletions(-) diff --git a/elisp/init-company.el b/elisp/init-company.el index 80feebdc..b3159f34 100644 --- a/elisp/init-company.el +++ b/elisp/init-company.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 10:02:00 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Fri Dec 27 22:11:06 2019 (-0500) +;; Last-Updated: Thu Jul 30 15:27:46 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d company company-tabnine @@ -60,7 +60,7 @@ ;; Number the candidates (use M-1, M-2 etc to select completions). (company-show-numbers t) :config - (unless *clangd* (delete 'company-clang company-backends)) + (unless clangd-p (delete 'company-clang company-backends)) (global-company-mode 1) (defun smarter-yas-expand-next-field-complete () "Try to `yas-expand' and `yas-next-field' at current cursor position. @@ -182,7 +182,7 @@ If failed try to complete the common part with `company-complete-common'" (t . nil))))) (advice-add #'company-box-icons--elisp :override #'my-company-box-icons--elisp) - (when (and *sys/gui* + (when (and (display-graphic-p) (require 'all-the-icons nil t)) (declare-function all-the-icons-faicon 'all-the-icons) (declare-function all-the-icons-material 'all-the-icons) diff --git a/elisp/init-const.el b/elisp/init-const.el index 20681bdf..8148056e 100644 --- a/elisp/init-const.el +++ b/elisp/init-const.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Mon Mar 18 14:20:54 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Fri Jun 19 16:36:11 2020 (-0400) +;; Last-Updated: Wed Aug 12 21:33:13 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d constants @@ -43,10 +43,6 @@ ;; -UserInfo ;; Consts -(defconst *sys/gui* - (display-graphic-p) - "Are we running on a GUI Emacs?") - (defconst *sys/win32* (eq system-type 'windows-nt) "Are we running on a WinTel system?") @@ -59,59 +55,22 @@ (eq system-type 'darwin) "Are we running on a Mac system?") -(defconst *sys/root* - (string-equal "root" (getenv "USER")) - "Are you a ROOT user?") - -(defconst *rg* - (executable-find "rg") - "Do we have ripgrep?") - -(defconst *find* - (executable-find "find") - "Do we have GNU find?") - -(defconst *python* +(defconst python-p (or (executable-find "python3") (and (executable-find "python") (> (length (shell-command-to-string "python --version | grep 'Python 3'")) 0))) "Do we have python3?") -(defconst *pip* +(defconst pip-p (or (executable-find "pip3") (and (executable-find "pip") (> (length (shell-command-to-string "pip --version | grep 'python 3'")) 0))) "Do we have pip3?") -(defconst *tr* - (executable-find "tr") - "Do we have tr?") - -(defconst *mvn* - (executable-find "mvn") - "Do we have Maven?") - -(defconst *clangd* +(defconst clangd-p (or (executable-find "clangd") ;; usually (executable-find "/usr/local/opt/llvm/bin/clangd")) ;; macOS "Do we have clangd?") - -(defconst *gcc* - (executable-find "gcc") - "Do we have gcc?") - -(defconst *git* - (executable-find "git") - "Do we have git?") - -(defconst *fcitx5* - (executable-find "fcitx5") - "Do we have GNU fcitx5?") - -(defconst *eaf-env* - (and *sys/linux* *sys/gui* *python* *pip* - (not (equal (shell-command-to-string "pip freeze | grep '^PyQt\\|PyQtWebEngine'") ""))) - "Check basic requirements for EAF to run.") ;; -Consts (provide 'init-const) diff --git a/elisp/init-eaf.el b/elisp/init-eaf.el index 4a86e3ed..58aabd9a 100644 --- a/elisp/init-eaf.el +++ b/elisp/init-eaf.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Tue Jun 4 00:26:09 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Sun Jul 12 22:28:39 2020 (-0400) +;; Last-Updated: Wed Aug 12 21:33:10 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d pdf-tools @@ -43,7 +43,8 @@ ;; EAFPac (use-package eaf :load-path (lambda () (expand-file-name "site-elisp/emacs-application-framework" user-emacs-directory)) - :if *eaf-env* + :if (and *sys/linux* (display-graphic-p) python-p pip-p + (not (equal (shell-command-to-string "pip freeze | grep '^PyQt\\|PyQtWebEngine'") ""))) :custom (eaf-find-alternate-file-in-dired t) (browse-url-browser-function 'eaf-open-browser) ;; Make EAF Browser my default browser @@ -71,7 +72,8 @@ (eaf-bind-key zoom_in "C-=" eaf-pdf-viewer-keybinding) (eaf-bind-key zoom_out "C--" eaf-pdf-viewer-keybinding) (eaf-bind-key take_photo "p" eaf-camera-keybinding) - (eaf-bind-key eaf-send-key-sequence "M-]" eaf-terminal-keybinding)) + (eaf-bind-key eaf-send-key-sequence "M-]" eaf-terminal-keybinding) + ) ;; -EAFPac diff --git a/elisp/init-epaint.el b/elisp/init-epaint.el index 2ba01850..a838127b 100644 --- a/elisp/init-epaint.el +++ b/elisp/init-epaint.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Mon Sep 16 15:47:34 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Mon Sep 16 16:17:43 2019 (-0400) +;; Last-Updated: Wed Aug 12 21:28:45 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d epaint @@ -37,12 +37,9 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; EPaintPac (use-package epaint - :if *sys/gui* + :if (display-graphic-p) :load-path (lambda () (expand-file-name "site-elisp/epaint" user-emacs-directory)) :commands (epaint) :init diff --git a/elisp/init-eww.el b/elisp/init-eww.el index 1afe3b21..c335e69f 100644 --- a/elisp/init-eww.el +++ b/elisp/init-eww.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 11:13:42 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Tue Dec 24 12:18:07 2019 (-0500) +;; Last-Updated: Thu Jul 30 15:31:57 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d eww @@ -49,7 +49,7 @@ (rename-buffer "eww" t))) :config ;; I am using EAF-Browser instead of EWW - (unless *eaf-env* + (unless eaf-env-p (setq browse-url-browser-function 'eww-browse-url))) ; Hit & to browse url with system browser ;; -EWWPac diff --git a/elisp/init-flycheck.el b/elisp/init-flycheck.el index 8cd93f41..0a3c6cab 100644 --- a/elisp/init-flycheck.el +++ b/elisp/init-flycheck.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 10:08:22 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Wed Feb 19 16:28:16 2020 (-0500) +;; Last-Updated: Wed Aug 12 21:29:06 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d flycheck @@ -37,9 +37,6 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; FlyCheckPac (use-package flycheck :defer t @@ -53,7 +50,7 @@ (flycheck-indication-mode 'right-fringe) :init (use-package flycheck-grammarly :defer t) - (if *sys/gui* + (if (display-graphic-p) (use-package flycheck-posframe :custom-face (flycheck-posframe-border-face ((t (:inherit default)))) :hook (flycheck-mode . flycheck-posframe-mode) diff --git a/elisp/init-fonts.el b/elisp/init-fonts.el index 672c4922..30318bfb 100644 --- a/elisp/init-fonts.el +++ b/elisp/init-fonts.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Thu Mar 14 17:32:54 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Tue Feb 4 19:34:55 2020 (-0500) +;; Last-Updated: Wed Aug 12 21:29:18 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d fonts @@ -37,9 +37,6 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; FontsList ;; Input Mono, Monaco Style, Line Height 1.3 download from http://input.fontbureau.com/ (defvar font-list '(("Input" . 11) ("SF Mono" . 12) ("Consolas" . 12) ("Love LetterTW" . 12.5)) @@ -64,12 +61,12 @@ (set-frame-font font-setting nil t) (add-to-list 'default-frame-alist (cons 'font font-setting))))) -(when *sys/gui* +(when (display-graphic-p) (change-font)) ;; -FontFun ;; ATIPac -(use-package all-the-icons :if *sys/gui*) +(use-package all-the-icons :if (display-graphic-p)) ;; -ATIPac (provide 'init-fonts) diff --git a/elisp/init-global-config.el b/elisp/init-global-config.el index 59d0fc82..95b603a9 100644 --- a/elisp/init-global-config.el +++ b/elisp/init-global-config.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Thu Mar 14 14:01:54 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Thu Jul 2 23:21:33 2020 (-0400) +;; Last-Updated: Wed Aug 12 21:29:30 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d @@ -72,7 +72,7 @@ (set-keyboard-coding-system 'utf-8) (setq locale-coding-system 'utf-8)) ;; Treat clipboard input as UTF-8 string first; compound text next, etc. -(when *sys/gui* +(when (display-graphic-p) (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))) ;; -UTF8Coding @@ -97,7 +97,12 @@ The original function deletes trailing whitespace of the current line." (delete-trailing-whitespace) (widen)))))) -(add-hook 'before-save-hook #'delete-trailing-whitespace-except-current-line) +(defun smart-delete-trailing-whitespace () + "Invoke `delete-trailing-whitespace-except-current-line' on selected major modes only." + (unless (member major-mode '(diff-mode)) + (delete-trailing-whitespace-except-current-line))) + +(add-hook 'before-save-hook #'smart-delete-trailing-whitespace) ;; Replace selection on insert (delete-selection-mode 1) diff --git a/elisp/init-indent.el b/elisp/init-indent.el index 5660b988..163a946b 100644 --- a/elisp/init-indent.el +++ b/elisp/init-indent.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 10:29:56 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Fri May 15 15:10:58 2020 (-0400) +;; Last-Updated: Wed Aug 12 21:29:37 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d highlight-indent-guides indentation @@ -37,12 +37,9 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; HighLightIndentPac (use-package highlight-indent-guides - :if *sys/gui* + :if (display-graphic-p) :diminish ;; Enable manually if needed, it a severe bug which potentially core-dumps Emacs ;; https://github.com/DarthFennec/highlight-indent-guides/issues/76 diff --git a/elisp/init-input-method.el b/elisp/init-input-method.el index 4b111c98..fe8643c5 100644 --- a/elisp/init-input-method.el +++ b/elisp/init-input-method.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Thu Jun 20 00:36:05 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Sun Jun 21 00:52:39 2020 (-0400) +;; Last-Updated: Thu Jul 30 15:29:14 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d init @@ -37,9 +37,6 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; PyimPac (use-package pyim :init diff --git a/elisp/init-java.el b/elisp/init-java.el index 3df2da65..cde41aa2 100644 --- a/elisp/init-java.el +++ b/elisp/init-java.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Thu Jul 4 21:26:24 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Wed Feb 19 16:09:18 2020 (-0500) +;; Last-Updated: Wed Aug 12 21:29:51 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d lsp-java java-one-click-run @@ -37,13 +37,10 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; LSPJavaPac (use-package lsp-java :after lsp-mode - :if *mvn* + :if (executable-find "mvn") :init (use-package request :defer t) :custom diff --git a/elisp/init-lsp.el b/elisp/init-lsp.el index 35edee66..5965f8e9 100644 --- a/elisp/init-lsp.el +++ b/elisp/init-lsp.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 10:42:09 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Thu Jun 18 13:16:46 2020 (-0400) +;; Last-Updated: Wed Aug 12 21:30:02 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d lsp @@ -37,9 +37,6 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; LSPPac (use-package lsp-mode :defer t @@ -82,7 +79,7 @@ (lsp-ui-sideline-show-code-actions nil) :config ;; Use lsp-ui-doc-webkit only in GUI - (if *sys/gui* + (if (display-graphic-p) (setq lsp-ui-doc-use-webkit t)) ;; WORKAROUND Hide mode-line of the lsp-ui-imenu buffer ;; https://github.com/emacs-lsp/lsp-ui/issues/243 diff --git a/elisp/init-magit.el b/elisp/init-magit.el index c6fe286c..c34a18db 100644 --- a/elisp/init-magit.el +++ b/elisp/init-magit.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 08:40:27 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Tue Jun 23 16:52:35 2020 (-0400) +;; Last-Updated: Thu Aug 6 13:24:16 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d magit @@ -37,13 +37,13 @@ ;; ;;; Code: -(eval-when-compile - (require 'init-const)) - ;; MagitPac (use-package magit - :if *git* - :bind ("C-x g" . magit-status) + :if (executable-find "git") + :bind + (("C-x g" . magit-status) + (:map magit-status-mode-map + ("M-RET" . magit-diff-visit-file-other-window))) :config (defun magit-log-follow-current-file () "A wrapper around `magit-log-buffer-file' with `--follow' argument." diff --git a/elisp/init-pdf.el b/elisp/init-pdf.el index d556d06f..f7e62597 100644 --- a/elisp/init-pdf.el +++ b/elisp/init-pdf.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Tue Jun 4 00:26:09 2019 (-0400) ;; Version: 1.0.0 -;; Last-Updated: Tue Jan 14 00:12:52 2020 (-0500) +;; Last-Updated: Thu Jul 30 15:31:57 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d pdf-tools @@ -43,7 +43,7 @@ ;; PDFToolsPac (use-package pdf-tools-install :ensure pdf-tools - :if (and *sys/gui* (not *sys/win32*) (not *eaf-env*)) + :if (and (display-graphic-p) (not *sys/win32*) (not eaf-env-p)) :mode "\\.pdf\\'" :commands (pdf-loader-install) :custom diff --git a/elisp/init-projectile.el b/elisp/init-projectile.el index 5f1333b4..ff6e9c45 100644 --- a/elisp/init-projectile.el +++ b/elisp/init-projectile.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Fri Mar 15 09:10:23 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Fri Jun 12 10:29:51 2020 (-0400) +;; Last-Updated: Thu Jul 30 15:27:05 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d projectile @@ -48,7 +48,8 @@ (projectile-completion-system 'ivy) :config (projectile-mode 1) - (when (and *sys/win32* *tr*) + (when (and *sys/win32* + (executable-find "tr")) (setq projectile-indexing-method 'alien)) (add-to-list 'projectile-globally-ignored-directories "node_modules")) ;; -ProjPac diff --git a/elisp/init-python.el b/elisp/init-python.el index 88a99115..a5afc275 100644 --- a/elisp/init-python.el +++ b/elisp/init-python.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Mon Jun 10 18:58:02 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Wed Mar 11 13:48:21 2020 (-0400) +;; Last-Updated: Thu Jul 30 15:59:34 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: lsp-python-ms @@ -55,7 +55,7 @@ ;; LSPPythonPac (use-package lsp-python-ms :after lsp-mode python - :if *python* + :if python-p :custom (lsp-python-executable-cmd "python3")) ;; -LSPPythonPac diff --git a/elisp/init-search.el b/elisp/init-search.el index ebb865bd..b5301160 100644 --- a/elisp/init-search.el +++ b/elisp/init-search.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Thu Mar 14 11:01:43 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Fri Jun 12 10:34:15 2020 (-0400) +;; Last-Updated: Wed Aug 12 21:31:57 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d color-rg rg @@ -38,8 +38,7 @@ ;;; Code: (eval-when-compile - (require 'init-global-config) - (require 'init-const)) + (require 'init-global-config)) ;; IvyPac (use-package ivy @@ -76,13 +75,16 @@ ;; ColorRGPac (use-package color-rg :load-path (lambda () (expand-file-name "site-elisp/color-rg" user-emacs-directory)) - :if *rg* + :if (executable-find "rg") :bind ("C-M-s" . color-rg-search-input)) ;; -ColorRGPac ;; FFIPPac (use-package find-file-in-project - :if *find* + :if (executable-find "find") + :init + (when (executable-find "fd") + (setq ffip-use-rust-fd t)) :bind (("C-z o" . ffap) ("C-z p" . ffip))) ;; -FFIPPac @@ -90,7 +92,7 @@ ;; SnailsPac (use-package snails :load-path (lambda () (expand-file-name "site-elisp/snails/" user-emacs-directory)) - :if *sys/gui* + :if (display-graphic-p) :custom-face (snails-content-buffer-face ((t (:background "#111" :height 110)))) (snails-input-buffer-face ((t (:background "#222" :foreground "gold" :height 110)))) diff --git a/elisp/init-shell.el b/elisp/init-shell.el index 12ac4a42..c29a8f55 100644 --- a/elisp/init-shell.el +++ b/elisp/init-shell.el @@ -6,7 +6,7 @@ ;; Copyright (C) 2019 Mingde (Matthew) Zeng ;; Created: Tue Mar 19 09:20:19 2019 (-0400) ;; Version: 2.0.0 -;; Last-Updated: Mon Mar 2 15:10:49 2020 (-0500) +;; Last-Updated: Thu Jul 30 15:24:34 2020 (-0400) ;; By: Mingde (Matthew) Zeng ;; URL: https://github.com/MatthewZMD/.emacs.d ;; Keywords: M-EMACS .emacs.d shell shell-here @@ -90,7 +90,7 @@ ;; TermKeysPac (use-package term-keys - :if (not *sys/gui*) + :if (not (display-graphic-p)) :config (term-keys-mode t)) ;; -TermKeysPac