4

Literal Programming Emacs Configure Literal Programming Emacs Configure

 3 years ago
source link: https://blog.oyanglul.us/emacs/literal-programming-emacs-config
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Literal Programming Emacs Configure Literal Programming Emacs Configure

Table of Contents

Theme

dracula dark theme

(use-package dracula-theme
  :config
  (load-theme 'dracula t))

Fonts

Download JetBrain Mono font.

(if (member "JetBrains Mono" (font-family-list))
    (set-frame-font "JetBrains Mono Light 15"))

(when (eq system-type 'gnu/linux)
  (dolist (charset '(kana han symbol cjk-misc bopomofo))
    (set-fontset-font (frame-parameter nil 'font) charset
                      (font-spec :family "Noto Sans CJK SC"))))

(global-prettify-symbols-mode 1)

Default Settings

;; Setting
(server-start)
(keyboard-translate ?\C-h ?\C-?)
(column-number-mode 1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(menu-bar-mode -1)
(delete-selection-mode 1)
(global-auto-revert-mode 1)
(electric-indent-mode t)

(setq-default
 make-backup-files nil
 indent-tabs-mode nil)
;; make unix lineendings default
 (setq default-buffer-file-coding-system 'utf-8-unix)
(when (eq system-type 'darwin)
  (setq mac-option-modifier 'alt)
  (setq mac-option-modifier 'super) ; make opt key do Super
  (setq mac-command-modifier 'meta))
(setenv "PATH" "/usr/local/bin:/usr/bin:/bin")
    (if (eq system-type 'gnu/linux)
(let ((path-from-shell (shell-command-to-string "/usr/bin/fish -c \"echo -n \\$PATH[1]; for val in \\$PATH[2..-1];echo -n \\\":\\$val\\\";end\"")))
  (setenv "PATH" path-from-shell)
  (setq exec-path (split-string path-from-shell ":")))
(let ((path-from-shell (shell-command-to-string "/usr/local/bin/fish -c \"echo -n \\$PATH[1]; for val in \\$PATH[2..-1];echo -n \\\":\\$val\\\";end\"")))
  (setenv "PATH" path-from-shell)
  (setq exec-path (split-string path-from-shell ":")))
        )

Modes

ace jump mode

You can move your cursor to ANY position ( across window and frame ) in emacs by using only 3 times key press.

(use-package ace-jump-mode
:ensure t
:bind
("C-c SPC" . ace-jump-mode)
("C-c u SPC" . ace-jump-mode-pop-mark)
("C-c l SPC" . ace-jump-line-mode))

company

text completion framework

(use-package company
  :config
   (add-hook 'after-init-hook 'global-company-mode)
   )

Dhall

(use-package dhall-mode
  :ensure t
  :config
  (setq
    ;; uncomment the next line to disable automatic format
    ;; dhall-format-at-save nil

    ;; comment the next line to use unicode syntax
    ;; dhall-format-arguments (\` ("--ascii"))

    ;; header-line is obsoleted by lsp-mode
    dhall-use-header-line nil))

expand region

(use-package expand-region
:bind
("C-8" . er/expand-region)
("C--" . er/contract-region))

Flyspell

(use-package flycheck
  :ensure t
  :init
  (global-flycheck-mode)
  :config
  (dolist (hook '(text-mode-hook))
    (add-hook hook (lambda ()
                     (flyspell-mode 1)
                     (add-to-list 'company-backends 'company-ispell)
                     (message "company-ispell enable")
                     )
              ))
  (dolist (hook '(prog-mode-hook))
    (add-hook hook (lambda ()
                     (flyspell-prog-mode)
                     (setq company-backends (delete 'company-ispell company-backends))
                     (message "company-ispell disable")
                     )))
  )
(use-package company-fish
:hook (shell-mode-hook . company-mode)
:init (add-to-list 'company-backends 'company-fish)
)

forge

;;(use-package forge
;;:after magit)
  (use-package helm
    :ensure t
    :bind
    ("M-x" . helm-M-x)
    ("C-x b" . helm-mini)
    ("M-y" . helm-show-kill-ring)
    :bind (:map helm-map
          ("<tab>" . helm-execute-persistent-action) ; rebind tab to run persistent action
          ("C-i" . helm-execute-persistent-action) ; make TAB works in terminal
          ("C-z" . helm-select-action))
    :config

    (helm-autoresize-mode 1)
    (setq 
     helm-M-x-fuzzy-match t
     helm-buffers-fuzzy-matching t
     helm-recentf-fuzzy-match t
     helm-ag-fuzzy-match t ;(ref: ag-fuzzy-match)
     helm-locate-fuzzy-match t
     )
    )
(use-package helm-swoop
  :ensure t
  :bind (("M-m" . helm-multi-swoop-projectile)
         ("M-M" . helm-swoop-back-to-last-point))
  :init
(bind-key "M-m" 'helm-swoop-from-isearch isearch-mode-map))

  (use-package projectile
:ensure t
  :bind-keymap
  ("C-c p" . projectile-command-map)
  :config
  (projectile-global-mode)
  (setq projectile-indexing-method 'alien
  projectile-enable-caching t
  projectile-completion-system 'helm))

  (use-package helm-projectile
:ensure t
    :config
    (helm-projectile-on)
    )
(use-package ido
  :bind
  :config
  (setq ido-everywhere t
        ido-enable-flex-matching t)
  (ido-mode 1))

indent guide

(use-package indent-guide
:hook (prog-mode . indent-guide-mode))

js2 mode

(use-package js2-mode
:config
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.sjs$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.es6$" . js2-mode))
(setq js2-allow-rhino-new-expr-initializer nil)
(setq js2-enter-indents-newline t)
(setq js2-global-externs '("module" "require" "buster" "sinon" "assert" "refute" "setTimeout" "clearTimeout" "setInterval" "clearInterval" "location" "__dirname" "console" "JSON"))
(setq js2-idle-timer-delay 0.1)
(setq js2-indent-on-enter-key nil)
(setq js2-mirror-mode nil)
(setq js2-strict-inconsistent-return-warning nil)
(setq js2-auto-indent-p t)
(setq js2-include-rhino-externs nil)
(setq js2-include-gears-externs nil)
(setq js2-concat-multiline-strings 'eol)
(setq js2-rebind-eol-bol-keys nil)
(setq js2-mode-show-parse-errors t)
(setq js2-mode-show-strict-warnings nil))

key chord

  (use-package key-chord
    :config
    (key-chord-mode 1)
    (setq key-chord-two-keys-delay 0.03)
    (key-chord-define-global "vr"     'vr/replace)
    (key-chord-define-global "ln"     'display-line-numbers-mode)
    (key-chord-define-global ",."     "<>\C-b")
)

Langtool

Install LanguageTool version 3.0 or later (and java) https://languagetool.org/

extract them into /usr/local/share/LanguageTool

(use-package langtool
:config
(setq langtool-language-tool-jar "/usr/local/share/LanguageTool/languagetool-commandline.jar"
      langtool-disabled-rules '("WHITESPACE_RULE"
                                "EN_UNPAIRED_BRACKETS"
                                "COMMA_PARENTHESIS_WHITESPACE"
                                "EN_QUOTES")
      langtool-default-language "en-US")
)

ligature

(when (cl-search "27." (emacs-version))
  (use-package ligature
    :ensure t
    :init
    (ligature-set-ligatures 'prog-mode '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
                                         ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
                                         "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
                                         "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
                                         "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
                                         "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
                                         "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
                                         "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
                                         ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
                                         "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
                                         "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
                                         "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
                                         "\\" "://"))
    (global-ligature-mode t))
  )

magit

(use-package magit
:bind
("C-x g" . magit-status))

multi cursor

(use-package multiple-cursors
:bind
("C-<" . mc/mark-previous-like-this)
 ("C->" . mc/mark-next-like-this)
 ("C-*" . mc/mark-all-like-this))

Nya mode

(use-package nyan-mode
:ensure t
:config (nyan-mode t))

on screen

(use-package on-screen
:ensure t
:config
(on-screen-global-mode 1)
(setq on-screen-highlight-method 'narrow-line))

org mode

(when (cl-search "27." (emacs-version))
  (require 'org-tempo))
(setq org-startup-folded 'content)
(setq org-startup-indented nil)
(setq org-startup-with-inline-images t)
(setq org-startup-truncated nil)
(setq org-src-tab-acts-natively t)

(setq js-indent-level 2)
(use-package org-crypt
:config 
(org-crypt-use-before-save-magic)
(setq org-crypt-key "A506C38D5CC847D0DF01134ADA8B833B52604E63")
(setq org-tags-exclude-from-inheritance '("crypt"))
)
(setq org-agenda-files (quote ("~/Dropbox/org")))
(setq org-refile-targets (quote ((nil :maxlevel . 9)
                                 (org-agenda-files :maxlevel . 9))))
    (setq org-directory "~/Dropbox/org")
    (setq org-default-notes-file "~/Dropbox/org/refile.org")

    ;; I use C-c c to start capture mode
    (global-set-key (kbd "C-c c") 'org-capture)
    (global-set-key (kbd "C-c a") 'org-agenda)

    ;; Capture templates for: TODO tasks, Notes, appointments, phone calls, meetings, and org-protocol
    (setq org-capture-templates
          (quote (("t" "Todo" entry (file+headline "~/Dropbox/org/refile.org" "Todos")
                   "* TODO %?\n%U\n%a\n" :clock-in t :clock-resume t)
                  ("n" "Note" entry (file+headline "~/Dropbox/org/note.org" "Notes")
                   "* %?\n%U\n%a\n" :clock-in t :clock-resume t)
                  ("w" "Work" entry (file+headline "~/Dropbox/org/myob.org" "Work Notes")
                   "* %?\n%U\n" :clock-in t :clock-resume t)
                  )))
  (setq org-refile-use-outline-path t)

  ; Targets complete directly with IDO
  (setq org-outline-path-complete-in-steps nil)
  ; Use IDO for both buffer and file completion and ido-everywhere to t
  (setq org-completion-use-ido t)
  (setq ido-everywhere t)
  (setq ido-max-directory-size 100000)
  (ido-mode (quote both))
  ; Use the current window when visiting files and buffers with ido
  (setq ido-default-file-method 'selected-window)
  (setq ido-default-buffer-method 'selected-window)
  ; Use the current window for indirect buffer display
  (setq org-indirect-buffer-display 'current-window)

pallet

(use-package pallet
:config
(pallet-mode t))

prompt

(defalias 'yes-or-no-p 'y-or-n-p)
(setq kill-buffer-query-functions
      (remq 'process-kill-buffer-query-function
            kill-buffer-query-functions))

PureScript

(use-package psc-ide
:init
(setq psc-ide-use-npm-bin t)
:config
(add-hook 'purescript-mode-hook
  (lambda ()
    (psc-ide-mode)
    (company-mode)
    (flycheck-mode)
    (turn-on-purescript-indentation)))

)

rainbow delimiter

(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode))

Restclient

(use-package restclient
  :config
  (add-to-list 'company-backends 'company-restclient))
;; :config
;; ;
                                        ; 
;; :hook (company-mode))

Scala Metals

;; Enable scala-mode for highlighting, indentation and motion commands
(use-package scala-mode
  :mode "\\.s\\(cala\\|bt\\)$")

;; Enable sbt mode for executing sbt commands
(use-package sbt-mode
  :commands sbt-start sbt-command
  :config
  ;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
  ;; allows using SPACE when in the minibuffer
  (substitute-key-definition
   'minibuffer-complete-word
   'self-insert-command
   minibuffer-local-completion-map)
   ;; sbt-supershell kills sbt-mode:  https://github.com/hvesalai/emacs-sbt-mode/issues/152
   (setq sbt:program-options '("-Dsbt.supershell=false"))
)

(use-package lsp-mode
  ;; Optional - enable lsp-mode automatically in scala files
  :hook  (scala-mode . lsp)
         (lsp-mode . lsp-lens-mode)
         (dhall-mode . lsp)
  :config (setq lsp-prefer-flymake nil))

;; Add metals backend for lsp-mode
(use-package lsp-metals)

;; Enable nice rendering of documentation on hover
(use-package lsp-ui)

;; Add company-lsp backend for metals
(use-package company-lsp)

shell-mode

(setq comint-output-filter-functions
      (remove 'ansi-color-process-output comint-output-filter-functions))

(add-hook 'shell-mode-hook
          (lambda ()
            ;; Disable font-locking in this buffer to improve performance
            (font-lock-mode -1)
            ;; Prevent font-locking from being re-enabled in this buffer
            (make-local-variable 'font-lock-function)
            (setq font-lock-function (lambda (_) nil))
            (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter nil t)))
(setenv "TERM" "xterm-256color")

smartparens

(use-package smartparens
  :init
  (require 'smartparens-config)
  :config
   (smartparens-global-mode t)
   (show-smartparens-global-mode t))

textmate

(use-package textmate
:init
(textmate-mode)
(bind-keys
 :map *textmate-mode-map*
 ("M--" . text-scale-decrease)
 ("M-=" . text-scale-increase)
 ("M-}" . textmate-shift-right)
 ("M-<backspace>" . kill-whole-line)
 ("M-c" . kill-ring-save)
 ("M-{" . textmate-shift-left)
 ("M-/" . comment-line)
 ("M-l" . textmate-select-line)
 ))

undo tree

(use-package undo-tree
  :init (global-undo-tree-mode))

unicode

(use-package unicode-fonts
   :ensure t
   :config
    (unicode-fonts-setup))

web-mode

(use-package web-mode
  :mode "\\.html$'" "\\.jsx$" "\\.tsx$"
  :init 
  (setq web-mode-markup-indent-offset 2)
  (setq web-mode-css-indent-offset 2)
  (setq web-mode-code-indent-offset 2)
  )

which key

     (use-package which-key
       :config
       (which-key-mode)
       (setq which-key-use-C-h-commands t)
       (setq which-key-paging-key "<f5>")
)

yasnippet

(use-package yasnippet
:config
(yas-global-mode 1))


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK