forked from muhaaliss/mydotfiles
597 lines
17 KiB
EmacsLisp
597 lines
17 KiB
EmacsLisp
;;; Author: Muha Aliss
|
||
;;; Mail: muhaaliss@pm.me
|
||
;;; Create: 07/09/2023
|
||
;;; Edit: 09/09/2023
|
||
|
||
|
||
|
||
|
||
|
||
;;; ---> Package
|
||
|
||
;; Package signature check disable
|
||
(when (version<= "25" emacs-version)
|
||
(setq package-check-signature nil))
|
||
|
||
|
||
|
||
;; List the packages you want
|
||
(setq package-list '(gnu-elpa gnu-elpa-keyring-update atom-one-dark-theme))
|
||
|
||
|
||
|
||
;; List the repositories containing them
|
||
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
|
||
("melpa" . "https://melpa.org/packages/")))
|
||
|
||
|
||
|
||
;; Activate all the packages (in particular autoloads)
|
||
(package-initialize)
|
||
|
||
|
||
|
||
;; Fetch the list of packages available
|
||
(unless package-archive-contents
|
||
(package-refresh-contents))
|
||
|
||
|
||
|
||
;; İnstall the missing packages
|
||
(dolist (package package-list)
|
||
(unless (package-installed-p package)
|
||
(package-install package)))
|
||
|
||
|
||
|
||
|
||
|
||
;;; ---> Interface
|
||
|
||
;; Hide welcome screen and open bookmark
|
||
(setq inhibit-splash-screen t)
|
||
(require 'bookmark)
|
||
(list-bookmarks)
|
||
(switch-to-buffer "*Bookmark List*")
|
||
|
||
|
||
|
||
;; Set cursor to i-beam
|
||
(modify-all-frames-parameters (list (cons 'cursor-type 'bar)))
|
||
|
||
|
||
|
||
;; Set a theme
|
||
(load-theme 'atom-one-dark t)
|
||
|
||
|
||
|
||
;; Set default window size
|
||
(if (display-graphic-p)
|
||
(progn
|
||
(setq initial-frame-alist
|
||
'(
|
||
(tool-bar-lines . 0)
|
||
(width . 110) ; chars
|
||
(height . 40) ; lines
|
||
;(background-color . "honeydew")
|
||
(left . 50)
|
||
(top . 50)))
|
||
(setq default-frame-alist
|
||
'(
|
||
(tool-bar-lines . 0)
|
||
(width . 110)
|
||
(height . 40)
|
||
;(background-color . "honeydew")
|
||
(left . 50)
|
||
(top . 50))))
|
||
(progn
|
||
(setq initial-frame-alist '( (tool-bar-lines . 0)))
|
||
(setq default-frame-alist '( (tool-bar-lines . 0)))))
|
||
|
||
|
||
|
||
;; Show line number global
|
||
(when (version<= "26.1" emacs-version)
|
||
(global-display-line-numbers-mode))
|
||
|
||
|
||
;; Highlight Current Line
|
||
(global-hl-line-mode 1)
|
||
|
||
|
||
|
||
;; Up/Down arrow move based on logical lines (newline char) or visual line
|
||
(setq line-move-visual nil)
|
||
|
||
|
||
|
||
;; Show cursor position within line
|
||
(column-number-mode 1)
|
||
|
||
|
||
|
||
;; Set default font
|
||
(cond
|
||
((string-equal system-type "windows-nt") ; Microsoft Windows
|
||
(when (member "Consolas" (font-family-list))
|
||
(set-frame-font "Consolas-12" t t)))
|
||
((string-equal system-type "darwin") ; macOS
|
||
(when (member "Menlo" (font-family-list))
|
||
(set-frame-font "Menlo-12" t t)))
|
||
((string-equal system-type "gnu/linux") ; linux
|
||
(when (member "Source Code Pro" (font-family-list))
|
||
(set-frame-font "Source Code Pro-12" t t))))
|
||
|
||
|
||
|
||
;; org mode syntax color embeded source code
|
||
(setq org-src-fontify-natively t)
|
||
|
||
|
||
|
||
|
||
|
||
;;; ---> Editing
|
||
|
||
;; Stop auto save and backup
|
||
(setq auto-save-default nil)
|
||
(setq make-backup-files nil)
|
||
(setq backup-by-copying t)
|
||
|
||
|
||
|
||
;; Turn on/off line wrap for current buffer.
|
||
(global-visual-line-mode 1)
|
||
|
||
|
||
|
||
;; Make typing delete/overwrites selected text
|
||
(delete-selection-mode 1)
|
||
|
||
|
||
|
||
;; Set default tab char's display width to 4 spaces
|
||
(setq-default tab-width 4)
|
||
|
||
|
||
|
||
;; Make indent commands use space only (never tab character)
|
||
(progn
|
||
(setq-default indent-tabs-mode nil))
|
||
|
||
|
||
|
||
;; Make tab key do indent first then completion.
|
||
(setq-default tab-always-indent nil)
|
||
|
||
|
||
|
||
;; Set highlighting brackets
|
||
(show-paren-mode 1)
|
||
(setq show-paren-style 'mixed)
|
||
|
||
|
||
|
||
;; Add support for pretty symbols mode
|
||
(global-prettify-symbols-mode 1)
|
||
(defun my-add-pretty-symbol ()
|
||
"make some word display as Unicode symbols"
|
||
(setq prettify-symbols-alist
|
||
'(
|
||
("->" . 8594) ; → 8594
|
||
("lambda" . 955) ; λ 955
|
||
("--->" . 10230) ; ⟶ 10230
|
||
("=>" . 8658) ; ⇒ 8658
|
||
("map" . 8614) ; ↦ 8614
|
||
)))
|
||
|
||
;; Pretty symbols hook for some major modes
|
||
(add-hook 'clojure-mode-hook 'my-add-pretty-symbol)
|
||
(add-hook 'haskell-mode-hook 'my-add-pretty-symbol)
|
||
(add-hook 'tex-mode-hook 'my-add-pretty-symbol)
|
||
(add-hook 'emacs-lisp-mode-hook 'my-add-pretty-symbol)
|
||
(add-hook 'python-mode-hook 'my-add-pretty-symbol)
|
||
|
||
|
||
|
||
;; Hippie expand keybindings
|
||
(global-set-key (kbd "C-t") 'hippie-expand)
|
||
|
||
;; Hippie expand to words only
|
||
(setq hippie-expand-try-functions-list
|
||
'(
|
||
try-expand-dabbrev
|
||
try-expand-dabbrev-all-buffers
|
||
;; try-expand-dabbrev-from-kill
|
||
try-complete-lisp-symbol-partially
|
||
try-complete-lisp-symbol
|
||
try-complete-file-name-partially
|
||
try-complete-file-name
|
||
;; try-expand-all-abbrevs
|
||
;; try-expand-list
|
||
;; try-expand-line
|
||
))
|
||
|
||
|
||
|
||
;; Select current line keybinding
|
||
(global-set-key (kbd "M-7") 'xah-select-line)
|
||
|
||
(defun xah-select-line ()
|
||
"Select current line. If region is active, extend selection downward by line.
|
||
If `visual-line-mode' is on, consider line as visual line.
|
||
|
||
URL `http://xahlee.info/emacs/emacs/modernization_mark-word.html'
|
||
Version: 2017-11-01 2021-03-19 2023-07-16"
|
||
(interactive)
|
||
(if (region-active-p)
|
||
(if visual-line-mode
|
||
(let ((xp1 (point)))
|
||
(end-of-visual-line 1)
|
||
(when (eq xp1 (point))
|
||
(end-of-visual-line 2)))
|
||
(progn
|
||
(forward-line 1)
|
||
(end-of-line)))
|
||
(if visual-line-mode
|
||
(progn (beginning-of-visual-line)
|
||
(push-mark (point) t t)
|
||
(end-of-visual-line))
|
||
(progn
|
||
(push-mark (line-beginning-position) t t)
|
||
(end-of-line)))))
|
||
|
||
;; Copy or cut current line if no selection keybindings
|
||
(global-set-key (kbd "<f2>") 'xah-cut-line-or-region) ; cut
|
||
(global-set-key (kbd "<f3>") 'xah-copy-line-or-region) ; copy
|
||
(global-set-key (kbd "<f4>") 'yank) ; paste
|
||
|
||
|
||
|
||
;; Copy current line if no selection
|
||
(defun xah-copy-line-or-region ()
|
||
"Copy current line or selection.
|
||
When called repeatedly, append copy subsequent lines.
|
||
When `universal-argument' is called first, copy whole buffer (respects `narrow-to-region').
|
||
|
||
URL `http://xahlee.info/emacs/emacs/emacs_copy_cut_current_line.html'
|
||
Version: 2010-05-21 2022-10-03"
|
||
(interactive)
|
||
(let ((inhibit-field-text-motion nil))
|
||
(if current-prefix-arg
|
||
(progn
|
||
(copy-region-as-kill (point-min) (point-max)))
|
||
(if (region-active-p)
|
||
(progn
|
||
(copy-region-as-kill (region-beginning) (region-end)))
|
||
(if (eq last-command this-command)
|
||
(if (eobp)
|
||
(progn )
|
||
(progn
|
||
(kill-append "\n" nil)
|
||
(kill-append
|
||
(buffer-substring-no-properties (line-beginning-position) (line-end-position))
|
||
nil)
|
||
(progn
|
||
(end-of-line)
|
||
(forward-char))))
|
||
(if (eobp)
|
||
(if (eq (char-before) 10 )
|
||
(progn )
|
||
(progn
|
||
(copy-region-as-kill (line-beginning-position) (line-end-position))
|
||
(end-of-line)))
|
||
(progn
|
||
(copy-region-as-kill (line-beginning-position) (line-end-position))
|
||
(end-of-line)
|
||
(forward-char))))))))
|
||
|
||
|
||
|
||
;; Cut current line if no selection
|
||
(defun xah-cut-line-or-region ()
|
||
"Cut current line or selection.
|
||
When `universal-argument' is called first, cut whole buffer (respects `narrow-to-region').
|
||
|
||
URL `http://xahlee.info/emacs/emacs/emacs_copy_cut_current_line.html'
|
||
Version: 2010-05-21 2015-06-10"
|
||
(interactive)
|
||
(if current-prefix-arg
|
||
(progn ; not using kill-region because we don't want to include previous kill
|
||
(kill-new (buffer-string))
|
||
(delete-region (point-min) (point-max)))
|
||
(progn (if (region-active-p)
|
||
(kill-region (region-beginning) (region-end) t)
|
||
(kill-region (line-beginning-position) (line-beginning-position 2))))))
|
||
|
||
|
||
|
||
;; Move line keybindings.
|
||
(global-set-key (kbd "M-<up>") 'move-line-up)
|
||
(global-set-key (kbd "M-<down>") 'move-line-down)
|
||
|
||
;; Move the current line up or down by N lines.
|
||
(defun move-line (n)
|
||
(interactive "p")
|
||
(setq col (current-column))
|
||
(beginning-of-line) (setq start (point))
|
||
(end-of-line) (forward-char) (setq end (point))
|
||
(let ((line-text (delete-and-extract-region start end)))
|
||
(forward-line n)
|
||
(insert line-text)
|
||
;; restore point to original column in moved line
|
||
(forward-line -1)
|
||
(forward-char col)))
|
||
|
||
(defmacro save-column (&rest body)
|
||
`(let ((column (current-column)))
|
||
(unwind-protect
|
||
(progn ,@body)
|
||
(move-to-column column))))
|
||
(put 'save-column 'lisp-indent-function 0)
|
||
|
||
(defun move-line-up ()
|
||
(interactive)
|
||
(save-column
|
||
(transpose-lines 1)
|
||
(forward-line -2)))
|
||
|
||
(defun move-line-down ()
|
||
(interactive)
|
||
(save-column
|
||
(forward-line 1)
|
||
(transpose-lines 1)
|
||
(forward-line -1)))
|
||
|
||
|
||
|
||
;; Delete the matching brackets
|
||
(defun xah-delete-forward-bracket-pairs (&optional DeleteInnerTextQ)
|
||
"Delete the matching brackets to the right of cursor including the inner text.
|
||
e.g. ▮(a b c)
|
||
|
||
In lisp code, if DeleteInnerTextQ is true, also delete the inner text.
|
||
|
||
After the command, mark is set at the left matching bracket position, so you can `exchange-point-and-mark' to select it.
|
||
|
||
This command assumes the char to the right of point is a left bracket or quote, and have a matching one after.
|
||
|
||
What char is considered bracket or quote is determined by current syntax table.
|
||
|
||
URL `http://xahlee.info/emacs/emacs/emacs_delete_backward_char_or_bracket_text.html'
|
||
Version: 2017-07-02 2023-07-30"
|
||
(interactive (list t))
|
||
(if DeleteInnerTextQ
|
||
(progn
|
||
(mark-sexp)
|
||
(kill-region (region-beginning) (region-end)))
|
||
(let ((xpt (point)))
|
||
(forward-sexp)
|
||
(delete-char -1)
|
||
(push-mark (point) t)
|
||
(goto-char xpt)
|
||
(delete-char 1))))
|
||
|
||
(defun xah-delete-backward-bracket-text ()
|
||
"Delete the matching brackets to the left of cursor, including the inner text.
|
||
e.g. (a b c)▮
|
||
|
||
This command assumes the left of cursor is a right bracket, and there is a matching one before it.
|
||
|
||
What char is considered bracket or quote is determined by current syntax table.
|
||
|
||
URL `http://xahlee.info/emacs/emacs/emacs_delete_backward_char_or_bracket_text.html'
|
||
Version: 2017-09-21 2023-07-30"
|
||
(interactive)
|
||
(progn
|
||
(forward-sexp -1)
|
||
(mark-sexp)
|
||
(kill-region (region-beginning) (region-end))))
|
||
|
||
(defun xah-delete-backward-bracket-pair ()
|
||
"Delete the matching brackets/quotes to the left of cursor.
|
||
After call, mark is set at the matching bracket position, so you can `exchange-point-and-mark' to select it.
|
||
|
||
This command assumes the left of point is a right bracket, and there is a matching one before it.
|
||
|
||
What char is considered bracket or quote is determined by current syntax table.
|
||
|
||
URL `http://xahlee.info/emacs/emacs/emacs_delete_backward_char_or_bracket_text.html'
|
||
Version: 2017-07-02"
|
||
(interactive)
|
||
(let ((xp0 (point)) xp1)
|
||
(forward-sexp -1)
|
||
(setq xp1 (point))
|
||
(goto-char xp0)
|
||
(delete-char -1)
|
||
(goto-char xp1)
|
||
(delete-char 1)
|
||
(push-mark (point) t)
|
||
(goto-char (- xp0 2))))
|
||
|
||
(defun xah-delete-backward-char-or-bracket-text ()
|
||
"Delete 1 character or delete quote/bracket pair and inner text.
|
||
If the char to the left of cursor is a matching pair, delete it along with inner text, push the deleted text to `kill-ring'.
|
||
|
||
What char is considered bracket or quote is determined by current syntax table.
|
||
|
||
If `universal-argument' is called first, do not delete inner text.
|
||
|
||
URL `http://xahlee.info/emacs/emacs/emacs_delete_backward_char_or_bracket_text.html'
|
||
Version: 2017-07-02 2023-07-22 2023-07-30"
|
||
(interactive)
|
||
(if (and delete-selection-mode (region-active-p))
|
||
(delete-region (region-beginning) (region-end))
|
||
(cond
|
||
((prog2 (backward-char) (looking-at "\\s)") (forward-char))
|
||
(if current-prefix-arg
|
||
(xah-delete-backward-bracket-pair)
|
||
(xah-delete-backward-bracket-text))
|
||
)
|
||
((prog2 (backward-char) (looking-at "\\s(") (forward-char))
|
||
(message "left of cursor is opening bracket")
|
||
(let (xpOpenBracketLeft
|
||
(xpOpenBracketRight (point)) xisComment)
|
||
(backward-char)
|
||
(setq xpOpenBracketLeft (point))
|
||
(goto-char xpOpenBracketRight)
|
||
(forward-char)
|
||
(setq xisComment (nth 4 (syntax-ppss)))
|
||
(if xisComment
|
||
(progn
|
||
(message "cursor is in comment")
|
||
(goto-char xpOpenBracketLeft)
|
||
(if (forward-comment 1)
|
||
(kill-region (point) xpOpenBracketLeft)
|
||
(message "error hSnRp: parsing comment failed.")))
|
||
(progn
|
||
(message "right 1 char of cursor is not in comment")
|
||
(goto-char xpOpenBracketLeft)
|
||
(forward-sexp)
|
||
(if current-prefix-arg
|
||
(xah-delete-backward-bracket-pair)
|
||
(xah-delete-backward-bracket-text))))))
|
||
((prog2 (backward-char) (looking-at "\\s\"") (forward-char))
|
||
(if (nth 3 (syntax-ppss))
|
||
(progn
|
||
(backward-char)
|
||
(xah-delete-forward-bracket-pairs (not current-prefix-arg)))
|
||
(if current-prefix-arg
|
||
(xah-delete-backward-bracket-pair)
|
||
(xah-delete-backward-bracket-text))))
|
||
(t
|
||
(delete-char -1)))))
|
||
|
||
;; Delete batching bracket keybindings
|
||
(global-set-key (kbd "M-<delete>") 'xah-delete-forward-bracket-pairs)
|
||
(global-set-key (kbd "M-S-<delete>") 'xah-delete-backward-bracket-text)
|
||
|
||
|
||
(defvar xah-brackets '("“”" "()" "[]" "{}" "<>" "<>" "()" "[]" "{}" "⦅⦆" "〚〛" "⦃⦄" "‹›" "«»" "「」" "〈〉" "《》" "【】" "〔〕" "⦗⦘" "『』" "〖〗" "〘〙" "「」" "⟦⟧" "⟨⟩" "⟪⟫" "⟮⟯" "⟬⟭" "⌈⌉" "⌊⌋" "⦇⦈" "⦉⦊" "❛❜" "❝❞" "❨❩" "❪❫" "❴❵" "❬❭" "❮❯" "❰❱" "❲❳" "〈〉" "⦑⦒" "⧼⧽" "﹙﹚" "﹛﹜" "﹝﹞" "⁽⁾" "₍₎" "⦋⦌" "⦍⦎" "⦏⦐" "⁅⁆" "⸢⸣" "⸤⸥" "⟅⟆" "⦓⦔" "⦕⦖" "⸦⸧" "⸨⸩" "⦅⦆")
|
||
"A list of strings, each element is a string of 2 chars, the left bracket and a matching right bracket.
|
||
Used by `xah-select-text-in-quote' and others.")
|
||
|
||
(defconst xah-left-brackets
|
||
(mapcar (lambda (x) (substring x 0 1)) xah-brackets)
|
||
"List of left bracket chars. Each element is a string.")
|
||
|
||
(defconst xah-right-brackets
|
||
(mapcar (lambda (x) (substring x 1 2)) xah-brackets)
|
||
"List of right bracket chars. Each element is a string.")
|
||
|
||
(defun xah-goto-matching-bracket ()
|
||
"Move cursor to the matching bracket.
|
||
If cursor is not on a bracket, call `backward-up-list'.
|
||
The list of brackets to jump to is defined by `xah-left-brackets' and `xah-right-brackets'.
|
||
|
||
URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
|
||
Version: 2016-11-22 2023-07-22"
|
||
(interactive)
|
||
(if (nth 3 (syntax-ppss))
|
||
(backward-up-list 1 'ESCAPE-STRINGS 'NO-SYNTAX-CROSSING)
|
||
(cond
|
||
((eq (char-after) ?\") (forward-sexp))
|
||
((eq (char-before) ?\") (backward-sexp))
|
||
((looking-at (regexp-opt xah-left-brackets))
|
||
(forward-sexp))
|
||
((prog2 (backward-char) (looking-at (regexp-opt xah-right-brackets)) (forward-char))
|
||
(backward-sexp))
|
||
(t (backward-up-list 1 'ESCAPE-STRINGS 'NO-SYNTAX-CROSSING)))))
|
||
|
||
;; Goto matching bracket keybindings
|
||
(global-set-key (kbd "M-<left>") 'xah-goto-matching-bracket)
|
||
(global-set-key (kbd "M-<right>") 'xah-goto-matching-bracket)
|
||
|
||
|
||
|
||
|
||
|
||
;;; ---> Buffer
|
||
|
||
;; Make ibuffer default
|
||
(defalias 'list-buffers 'ibuffer)
|
||
|
||
;; Minibuffer setup
|
||
(progn
|
||
(setq enable-recursive-minibuffers t)
|
||
(savehist-mode 0)
|
||
;; big minibuffer height, for ido to show choices vertically
|
||
(setq max-mini-window-height 0.5)
|
||
;; minibuffer, stop cursor going into prompt
|
||
(customize-set-variable
|
||
'minibuffer-prompt-properties
|
||
(quote (read-only t cursor-intangible t face minibuffer-prompt))))
|
||
|
||
;; Make buffer switch command do suggestions, also for find-file command
|
||
(if (version< emacs-version "28.1")
|
||
(progn
|
||
(progn
|
||
(require 'ido)
|
||
(ido-mode 1)
|
||
;; show choices vertically
|
||
(setf (nth 2 ido-decorations) "\n")
|
||
;; show any name that has the chars you typed
|
||
(setq ido-enable-flex-matching t)
|
||
;; use current pane for newly opened file
|
||
(setq ido-default-file-method 'selected-window)
|
||
;; use current pane for newly switched buffer
|
||
(setq ido-default-buffer-method 'selected-window)
|
||
)
|
||
(progn
|
||
;; minibuffer enhanced completion icomplete
|
||
(require 'icomplete)
|
||
(icomplete-mode 1)
|
||
;; show choices vertically
|
||
(setq icomplete-separator "\n")
|
||
(setq icomplete-hide-common-prefix nil)
|
||
(setq icomplete-in-buffer t)
|
||
(define-key icomplete-minibuffer-map (kbd "<right>") 'icomplete-forward-completions)
|
||
(define-key icomplete-minibuffer-map (kbd "<left>") 'icomplete-backward-completions)))
|
||
(fido-vertical-mode 1))
|
||
|
||
|
||
|
||
;; Use short answer
|
||
(if (version< emacs-version "28.1")
|
||
(defalias 'yes-or-no-p 'y-or-n-p)
|
||
(setq use-short-answers t))
|
||
|
||
|
||
|
||
|
||
|
||
;;; ---> Load other .el files
|
||
|
||
(load "~/.emacs.d/my-abbrev.el")
|
||
|
||
|
||
|
||
|
||
|
||
;;; ---> Get value PATH
|
||
|
||
;; get value of env var PATH
|
||
(getenv "PATH")
|
||
|
||
|
||
|
||
|
||
|
||
;;; ---> Emacs auto added
|
||
|
||
(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 '(atom-one-dark))
|
||
'(custom-safe-themes
|
||
'("0c860c4fe9df8cff6484c54d2ae263f19d935e4ff57019999edbda9c7eda50b8" default))
|
||
'(package-selected-packages '(gnu-elpa-keyring-update gnu-elpa atom-one-dark-theme)))
|
||
(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.
|
||
)
|