Skip to content

Commit

Permalink
simplify init-const
Browse files Browse the repository at this point in the history
Signed-off-by: Mingde (Matthew) Zeng <[email protected]>
  • Loading branch information
MatthewZMD committed Aug 13, 2020
1 parent 01ec2b0 commit 31c2724
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 111 deletions.
6 changes: 3 additions & 3 deletions elisp/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
49 changes: 4 additions & 45 deletions elisp/init-const.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?")
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions elisp/init-eaf.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
7 changes: 2 additions & 5 deletions elisp/init-epaint.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions elisp/init-eww.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
7 changes: 2 additions & 5 deletions elisp/init-flycheck.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,9 +37,6 @@
;;
;;; Code:

(eval-when-compile
(require 'init-const))

;; FlyCheckPac
(use-package flycheck
:defer t
Expand All @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions elisp/init-fonts.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions elisp/init-global-config.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions elisp/init-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions elisp/init-input-method.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,9 +37,6 @@
;;
;;; Code:

(eval-when-compile
(require 'init-const))

;; PyimPac
(use-package pyim
:init
Expand Down
7 changes: 2 additions & 5 deletions elisp/init-java.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions elisp/init-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,9 +37,6 @@
;;
;;; Code:

(eval-when-compile
(require 'init-const))

;; LSPPac
(use-package lsp-mode
:defer t
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions elisp/init-magit.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
Loading

0 comments on commit 31c2724

Please sign in to comment.