Skip to content

Instantly share code, notes, and snippets.

@avatar-lavventura
Last active January 9, 2026 17:34
Show Gist options
  • Select an option

  • Save avatar-lavventura/0dc025d1a7e13f5b0a16c88edfbb5b3c to your computer and use it in GitHub Desktop.

Select an option

Save avatar-lavventura/0dc025d1a7e13f5b0a16c88edfbb5b3c to your computer and use it in GitHub Desktop.
;; help links
;; https://github.com/magit/magit/discussions/4674#discussioncomment-2668452
;; magit-blob-previous
;; magit-blob-next
;; * some links:
;; __ http://www.mattduck.com/2021-05-upgrading-to-emacs-28.html
(require 'package) ;; https://stackoverflow.com/a/14838150/2402577
(setq message-log-max t)
;; (when (eq system-type 'darwin)
;; (setq debug-on-error t))
(setq user-full-name "Alper Alimoglu")
(setq user-mail-address "[email protected]")
(setq user-init-file (or load-file-name (buffer-file-name)))
(setq user-emacs-directory (file-name-directory user-init-file))
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("tromey" . "http://tromey.com/elpa/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")))
(add-hook 'minibuffer-setup-hook
(lambda () (setq truncate-lines nil)))
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(unless package-archive-contents
(package-refresh-contents))
(autoload 'markdown-mode "markdown-mode.el"
"Major mode for editing Markdown files" t)
;;(if (not (package-installed-p 'lsp-mode))
;; (progn
;; (package-install 'lsp-mode)))
(defalias 'display-buffer-in-major-side-window 'window--make-major-side-window)
;; Minimize garbage collection during startup
(setq gc-cons-threshold most-positive-fixnum)
;; Lower threshold back to 8 MiB (default is 800kB)
(add-hook 'emacs-startup-hook
(lambda ()
(setq gc-cons-threshold (expt 2 23))))
(defvar my-overriding-binding-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [?\C-h] 'delete-backward-char)
(define-key map [?\M-h] 'backward-kill-word)
map))
(define-minor-mode my-overriding-binding-mode
"Personal global key-bindings."
:global t)
(my-overriding-binding-mode 1)
;; (setq fast-but-imprecise-scrolling 't) ;;keep cursor at same position when scrolling ??
(setq fast-but-imprecise-scrolling nil)
(setq scroll-preserve-screen-position 1)
(setq max-lisp-eval-depth 10000)
(setq auto-window-vscroll nil)
(setq help-window-select t)
(setq inhibit-splash-screen t)
(setq inhibit-startup-message t)
(setq initial-scratch-message "")
(setq package-check-signature nil)
(setq inhibit-startup-buffer-menu t)
(setq create-lockfiles nil)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
(setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
(setq use-dialog-box nil) ;; Disable dialog boxes since they weren't working in Mac OSX
(setq vc-follow-symlinks t)
(setq smooth-scroll-margin 4)
(setq ad-redefinition-action 'accept)
(setq inhibit-default-init t)
(setq inhibit-startup-screen t)
(setq column-number-mode t)
(setq lazy-highlight-interval 0)
(setq completion-show-help nil)
(setq compilation-ask-about-save nil)
(setq xterm-extra-capabilities nil) ;; https://emacs.stackexchange.com/a/41004/18414
(setq compilation-save-buffers-predicate '(lambda () nil)) ;; don't save *anything*
(setq fill-column 135) ;; https://emacs.stackexchange.com/a/68690/18414 ;; (setq fill-column 80)
(setq dired-deletion-confirmer #'y-or-n-p)
(setq server-client-instructions nil)
(setq comp-deferred-compilation t)
(setq comp-async-report-warnings-errors nil)
(setq company-auto-complete t)
(setq visible-bell nil
ring-bell-function #'ignore)
;; (setq-default case-fold-search nil) ;; https://stackoverflow.com/a/1481665/2402577 ;; case-sensitive
;; (setq case-fold-search nil)
;; (add-to-list 'load-path "~/.emacs.d/markdown-mode")
(setq use-short-answers t)
(fset 'yes-or-no-p 'y-or-n-p)
(if (display-graphic-p)
(progn
(tool-bar-mode -1)
(scroll-bar-mode -1) ;; disable visible scrollbar
(set-fringe-mode 10))) ;; give some breathing room
;; ------------------------------------------------------
;; (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;; (scroll-bar-mode -1)
;; (set-fringe-mode 10)
;; ------------------------------------------------------
(tool-bar-mode -1) ;; disable the toolbar
(tooltip-mode -1) ;; disable tooltips
(menu-bar-mode -1) ;; disable the menu bar
(global-auto-revert-mode 1) ;; auto revert mode
(transient-mark-mode 1)
(delete-selection-mode 1) ;; Overwrite selected text
(defun my-bottom ()
(interactive)
(let* ((height (window-height)))
(goto-char (point-max))
(set-window-start
(selected-window)
(min
(save-excursion ;; new point
(forward-line (- (/ height 2)))
(point))
(save-excursion ;; max point
(goto-char (point-max))
(beginning-of-line)
(forward-line (- (- height (+ 1 (* 2 scroll-margin)))))
(point)))))
(redisplay)
(end-of-visual-line)
(forward-line (/ (window-height
(selected-window)) 2)))
(global-set-key "\C-x\ ." 'my-bottom)
(global-set-key (kbd "C-x C-.") 'my-bottom)
(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "M-?") 'help)
(add-to-list 'load-path "~/.emacs.d/themes")
(add-to-list 'load-path "~/.emacs.d/lisp")
(add-to-list 'load-path "~/.emacs.d/config")
(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet")
(load "packages.el")
(load "diction.el")
(load "dracula-theme.el")
(load "writegood-mode.el")
(load "sphinx-doc.el")
;; https://emacs.stackexchange.com/a/77055/18414
(defun my-vertico-next (&optional n)
"Circulate without returning to the prompt line"
(interactive "p")
(let ((index (+ vertico--index (or n 1))))
(vertico--goto
(if (= vertico--total 0) -1 (mod index vertico--total)))))
(define-key vertico-map (kbd "TAB") 'my-vertico-next)
;; (add-to-list 'auto-mode-alist '("/Dockerfile\\'" . docker-compose-mode))
(add-to-list 'auto-mode-alist '("/Dockerfile\\'" . dockerfile-mode))
(add-to-list 'auto-mode-alist '("/emacs\\'" . lisp-mode))
(add-to-list 'auto-mode-alist '("/emacs_kama\\'" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.html\\'" . html-mode))
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;;
(setq my-skippable-buffer-regexp ;; ignore in the recentf moving buffer left and right
(rx bos (or (or "*Packages*" "*xref*" ".emacs" "*Compile-Log*" "*Ibuffer*" "*Python*"
"*scratch*" "*Help*" "*pylsp*" "*lsp-log*" "*Ido Completions*"
"dracula-theme.el" "*Helm Flyspell*" "*lsp-performance*" "TODO.org_archive"
"*Async-native-compile-log*" ".tmux.conf" "*apheleia-prettier-log*"
"*bash-ls::stderr*" "*Helm Flyspell*" "*helm find files*"
"*bash-ls*" "*eshell*" "dummy_file.txt" "*Warnings*" "*pylsp::stderr*"
".aliases" "*python-black errors*" "*Flycheck checkers*" "*Native-compile-Log*"
"*Colors*" "*Customize Face: Xref Match*" "*Find*" "config.yaml" "*Python*"
"*helm find files*" "*vc*" "*apheleia-black-log*")
(seq "magit" (zero-or-more anything))
(seq "*Man" (zero-or-more anything))
(seq (zero-or-more anything) ".ls")
(seq (zero-or-more anything) ".txt"))
eos)) ;; https://emacs.stackexchange.com/a/17694/18414
(defun my-change-buffer (change-buffer)
"Call CHANGE-BUFFER until `my-skippable-buffer-regexp' doesn't match."
(let ((initial (current-buffer)))
(funcall change-buffer)
(let ((first-change (current-buffer)))
(catch 'cl-loop
(while (string-match-p my-skippable-buffer-regexp (buffer-name))
(funcall change-buffer)
(when (eq (current-buffer) first-change)
(switch-to-buffer initial)
(throw 'cl-loop t)))))))
(defun my-next-buffer ()
(interactive)
(my-change-buffer 'next-buffer))
(defun my-previous-buffer ()
(interactive)
(my-change-buffer 'previous-buffer))
(global-set-key [remap next-buffer] 'my-next-buffer)
(global-set-key [remap previous-buffer] 'my-previous-buffer)
(global-set-key (kbd "M-k") 'previous-buffer)
(global-set-key (kbd "M-l") 'next-buffer)
(defun my_view-scroll-half-page-forward ()
(interactive)
(View-scroll-half-page-forward)
(recenter))
(defun my_view-scroll-half-page-backward ()
(interactive)
(View-scroll-half-page-backward)
(recenter))
(global-set-key "\C-v" 'my_view-scroll-half-page-forward)
(global-set-key "\M-v" 'my_view-scroll-half-page-backward)
(add-hook 'emacs-startup-hook (lambda ()
(when (get-buffer "*scratch*")
(kill-buffer "*scratch*"))))
(load-theme 'dracula t)
(defun query-replace-region-or-from-top ()
(interactive)
(let ((case-fold-search nil)) ;; case sensetive for replace words
(progn
(let ((orig-point (point)))
(if (use-region-p)
(call-interactively 'query-replace)
(save-excursion
(goto-char (point-min))
(call-interactively 'query-replace)))
(message "Back to old point.")
(goto-char orig-point)))))
(global-set-key "\C-x\C-r" 'query-replace-region-or-from-top)
(global-set-key "\C-x\ ," 'beginning-of-buffer)
(global-set-key (kbd "C-x C-,") 'beginning-of-buffer)
(global-set-key "\C-x\ ." 'end-of-buffer)
(defun comment-dwim-line (&optional arg)
(interactive "*P")
(comment-normalize-vars)
(if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
(comment-or-uncomment-region (point) (line-end-position))
(let ((comment-column (current-column)))
(comment-dwim arg))))
(global-set-key (kbd "C-c C-;") 'comment-dwim-line)
(global-set-key (kbd "C-c ;") 'comment-dwim-line)
(setq consult-project-root-function
(lambda ()
(when-let (project (project-current))
(car (project-roots project)))))
(defun bk-kill-buffers (regexp)
"Kill buffers matching REGEXP without asking for confirmation."
(interactive "sKill buffers matching this regular expression: ")
(cl-flet ((kill-buffer-ask (buffer) (kill-buffer buffer)))
(kill-matching-buffers regexp)))
(defun save-all-check-paren ()
(interactive)
;; https://stackoverflow.com/a/10088995/2402577
(if (bound-and-true-p flycheck-mode)
(flycheck-buffer))
(check-parens)
(let ((message-log-max nil)
(inhibit-message t))
(save-some-buffers t)))
(defun save-all ()
(interactive)
(let ((message-log-max nil)
(inhibit-message t))
(save-some-buffers t)))
(defun save-all-bib ()
(interactive)
(let ((message-log-max nil)
(inhibit-message t))
;; (bibtex-fill-entry)
;; (bibtex-clean-entry)
(bibtex-reformat)
(save-some-buffers t)))
;; (defun save-all-tex ()
;; (interactive)
;; (let ((message-log-max nil)
;; (inhibit-message t))
;; (flycheck-buffer)
;; (save-some-buffers t)))
(define-key ctl-x-map "\C-s" 'save-all)
(global-set-key (kbd "C-x s") 'save-all)
(global-set-key (kbd "C-x C-s") 'save-all)
(define-key python-mode-map (kbd "C-x s") 'save-all-check-paren)
(define-key python-mode-map (kbd "C-x C-s") 'save-all-check-paren)
(define-key bibtex-mode-map (kbd "C-x s") 'save-all-bib)
(define-key bibtex-mode-map (kbd "C-x C-s") 'save-all-bib)
(eval-after-load 'tex-mode
'(define-key latex-mode-map (kbd "C-x C-s") 'save-all))
(eval-after-load 'tex-mode
'(define-key latex-mode-map (kbd "C-x s") 'save-all))
(eval-after-load 'tex-mode
'(define-key latex-mode-map (kbd "C-x ,") 'beginning-of-buffer))
(eval-after-load 'tex-mode
'(define-key latex-mode-map (kbd "C-x C-,") 'beginning-of-buffer))
(defvar mode-line-cleaner-alist
`((auto-complete-mode . " α")
(paredit-mode . " π")
(my-keys-minor-mode . "")
(eldoc-mode . "")
(abbrev-mode . "")
(hi-lock-mode . "")
(python-mode . "Py")
(emacs-lisp-mode . "EL")
(nxhtml-mode . "nx")))
(defun clean-mode-line ()
(interactive)
(cl-loop for cleaner in mode-line-cleaner-alist
do (let* ((mode (car cleaner))
(mode-str (cdr cleaner))
(old-mode-str (cdr (assq mode minor-mode-alist))))
(when old-mode-str
(setcar old-mode-str mode-str))
;; major mode
(when (eq mode major-mode)
(setq mode-name mode-str)))))
(add-hook 'after-change-major-mode-hook 'clean-mode-line)
(defalias 'flymake-report-status 'flymake-report-status-slim)
(defun flymake-report-status-slim (e-w &optional status)
(when e-w
(setq flymake-mode-line-e-w e-w))
(when status
(setq flymake-mode-line-status status))
(let* ((mode-line " Φ"))
(when (> (length flymake-mode-line-e-w) 0)
(setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
(setq mode-line (concat mode-line flymake-mode-line-status))
(setq flymake-mode-line mode-line)
(force-mode-line-update)))
;; https://emacs.stackexchange.com/questions/16469/how-to-merge-git-conflicts-in-emacs
(eval-after-load 'smerge-mode
(lambda ()
(define-key smerge-mode-map (kbd "C-c v") smerge-basic-map)
(define-key smerge-mode-map (kbd "C-c C-v") smerge-basic-map)))
(defun smerge-next-safe ()
"Return t on success, nil otherwise"
(ignore-errors (not (smerge-next))))
(defun next-conflict ()
(interactive)
(let ((buffer (current-buffer)))
(when (not (smerge-next-safe))
(vc-find-conflicted-file)
(when (eq buffer (current-buffer))
(let ((prev-pos (point)))
(goto-char (point-min))
(unless (smerge-next-safe)
(goto-char prev-pos)
(message "No conflicts found")))))))
(global-set-key (kbd "C-c n") 'next-conflict)
(load "smart-quotes.el")
;; (load "synonyms.el")
;; (setq flymake-solidity-executable "/usr/bin/solc")
;; (setq solidity-solc-path "/usr/local/bin/solc")
(setq load-prefer-newer t)
(setq savehist-file "~/.emacs.d/tmp/savehist")
(cancel-function-timers 'auto-revert-buffers) ;; TeX-fold-comment
(add-to-list 'auto-mode-alist '("\\.sol\\'" . solidity-mode))
(global-set-key "\C-x\C-p" 'beginning-of-defun)
(global-set-key "\C-x\C-n" 'end-of-defun)
(global-set-key "\C-x\C-d" 'goto-line)
(global-set-key "\M-c" 'nil)
(global-set-key (kbd "C-x C-i")
(lambda ()
(interactive)
(kill-new (thing-at-point 'symbol))))
(defun replace-regexp-entire-buffer (pattern replacement)
"Perform regular-expression replacement throughout buffer."
(interactive
(let ((args (query-replace-read-args "Replace" t)))
(setcdr (cdr args) nil) ; remove third value returned from query---args
args))
(save-excursion
(goto-char (point-min))
(while (re-search-forward pattern nil t)
(replace-match replacement))))
(global-set-key (kbd "C-0") nil)
(global-set-key [(control t)] 'nil)
(global-visual-line-mode 1)
(bind-key "C-l" 'backward-word)
(defun backward-delete-word (arg)
"Delete characters backward until encountering the beginning of
a word. With argument ARG, do this that many times."
(interactive "p")
(delete-region (point) (progn (backward-word arg) (point))))
(setq-default truncate-lines t)
(setq-default c-basic-offset 4)
;; Turn on warn highlighting for characters outside of the 'width' char limit
(defun my-set-fill-column (arg)
"Set `fill-column' to specified argument.
Use \\[universal-argument] followed by a number to specify a column.
Just \\[universal-argument] as argument means to use the current column."
(interactive
(list (or current-prefix-arg
;; We used to use current-column silently, but C-x f is too easily
;; typed as a typo for C-x C-f, so we turned it into an error and
;; now an interactive prompt.
(read-number "Set fill-column to: " (current-column)))))
(if (consp arg)
(setq arg (current-column)))
(if (not (integerp arg))
;; Disallow missing argument; it's probably a typo for C-x C-f.
(error "my-set-fill-column requires an explicit argument")
;; (message "Fill column set to %d (was %d)" arg fill-column) <<< COMMENT OUT THIS LINE
(setq fill-column arg)))
'(font-lock-comment-face ((t (:foreground "MediumAquamarine"))))
(defun jpk/LaTeX-mode-hook () ;; stackoverflow.com/a/34660219/2402577
(company-mode -1))
(add-hook 'LaTeX-mode-hook 'jpk/LaTeX-mode-hook) ;; Disable word suggestions pop-up
;; (add-hook 'markdown-mode 'jpk/LaTeX-mode-hook)
;; (setq recentf-auto-cleanup 'never)
(defun my-insert-import (to_insert)
(newline)
(if (s-starts-with? "from" (s-trim to_insert)) (insert (s-trim to_insert))
(insert "import " to_insert))
)
(setq py-isort-options '("--force_single_line_imports"))
(setq flymake-start-on-flymake-mode nil)
(setq mark-even-if-inactive nil)
(setq uniquify-buffer-name-style 'reverse)
(setq frame-title-format
(list (format "%s %%S: %%j " (system-name))
'(buffer-file-name "%f" (dired-directory dired-directory "%b"))))
(defun my-find-file-check-make-large-file-read-only-hook ()
"If a file is over a given size, make the buffer read only."
(when (> (buffer-size) (* 1024 1024))
(buffer-disable-undo) ;; (setq buffer-read-only t)
(fundamental-mode)))
(add-hook 'find-file-hook 'my-find-file-check-make-large-file-read-only-hook)
(setq ibuffer-saved-filter-groups ;; emacswiki.org/emacs/IbufferMode
(quote (("default"
("dired" (mode . dired-mode))
("org" (name . "^.*org$"))
("web" (or (mode . web-mode) (mode . js2-mode)))
("shell" (or (mode . eshell-mode) (mode . shell-mode)))
("mu4e" (name . "\*mu4e\*"))
("ebloc-broker/"
(filename . "ebloc-broker/"))
("Default" (or
(mode . python-mode)
(mode . c++-mode)))
("emacs" (or
(name . "^\\*magit\\*$")
(name . "^\\*scratch\\*$")
;; (name . "^\\*Messages\\*$")))
)))))
)
(add-hook 'ibuffer-hook (lambda ()
(ibuffer-filter-by-size-gt 0)))
(add-hook 'ibuffer-mode-hook
(lambda ()
(ibuffer-auto-mode 1)
(ibuffer-switch-to-saved-filter-groups "default")))
(setq ibuffer-show-empty-filter-groups nil)
(setq ibuffer-expert t)
(defadvice ibuffer-update-title-and-summary (after remove-column-titles)
(with-current-buffer
(set-buffer "*Ibuffer*")
(read-only-mode 0)
(goto-char 1)
(search-forward "-\n" nil t)
(delete-region 1 (point))
(let ((window-min-height 1))
;; save a little screen estate
(shrink-window-if-larger-than-buffer))
(read-only-mode)))
(ad-activate 'ibuffer-update-title-and-summary)
(define-ibuffer-column size-h ;; Use human readable size column instead of original one
(:name "Size" :inline t)
(cond
((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
(t (format "%8d" (buffer-size)))))
;; Modify the default ibuffer-formats
(setq ibuffer-formats
'((mark modified read-only " "
(name 18 18 :left :elide)
" "
(size-h 9 -1 :right)
" "
(mode 16 16 :left :elide)
" "
filename-and-process)))
;; Ensure ibuffer opens with point at the current buffer's entry.
(defadvice ibuffer
(around ibuffer-point-to-most-recent) ()
"Open ibuffer with cursor pointed to most recent buffer name."
(let ((recent-buffer-name (buffer-name)))
ad-do-it
(ibuffer-jump-to-buffer recent-buffer-name)))
(ad-activate 'ibuffer)
(defun ibuffer-advance-motion (direction)
(forward-line direction)
(beginning-of-line)
(if (not (get-text-property (point) 'ibuffer-filter-group-name))
t
(ibuffer-skip-properties '(ibuffer-filter-group-name)
direction)
nil))
(defun ibuffer-previous-line ()
(interactive) (previous-line)
(if (<= (line-number-at-pos) 2)
(goto-line (- (count-lines (point-min) (point-max)) 2))))
(defun ibuffer-next-line (&optional arg)
"move forward arg lines, wrapping around the list if necessary."
(interactive "P")
(or arg (setq arg 1))
(let (err1 err2)
(while (> arg 0)
(cl-decf arg)
(setq err1 (ibuffer-advance-motion 1)
err2 (if (not (get-text-property (point) 'ibuffer-summary))
t
(goto-char (point-min))
(beginning-of-line)
(ibuffer-skip-properties '(ibuffer-summary
ibuffer-filter-group-name
ibuffer-title)
1)
nil)))
(and err1 err2)))
(defun ibuffer-next-header ()
(interactive)
(while (ibuffer-next-line)))
(defun ibuffer-previous-header ()
(interactive)
(while (ibuffer-previous-line)))
(define-key ibuffer-mode-map (kbd "C-p") 'ibuffer-previous-line)
(define-key ibuffer-mode-map (kbd "C-n") 'ibuffer-next-line)
(define-key ibuffer-mode-map (kbd "C-x C-f") 'ibuffer-jump-to-buffer)
(define-key ibuffer-mode-map (kbd "M-p") 'ibuffer-previous-header)
(define-key ibuffer-mode-map (kbd "M-n") 'ibuffer-next-header)
(define-key ibuffer-mode-map (kbd "C-q") 'quit-window)
(set-face-attribute 'default nil :height 100)
(defmacro with-suppressed-message (&rest body)
"Suppress new messages temporarily in the echo area and the `*Messages*' buffer while BODY is evaluated."
(declare (indent 0))
(let ((message-log-max nil))
`(with-temp-message (or (current-message) "") ,@body)))
(defun remove-scratch-buffer ()
(if (get-buffer "*scratch*")
(kill-buffer "*scratch*")))
(add-hook 'minibuffer-exit-hook
'(lambda ()
(let ((buffer "*Completions*"))
(and (get-buffer buffer)
(kill-buffer buffer)))))
;; Show only one active window when opening multiple files at the same time.
(add-hook 'window-setup-hook 'delete-other-windows)
(global-set-key (kbd "C-x o") 'other-window)
(global-set-key "\C-x\C-o" 'other-window)
(global-set-key (kbd "M-o") 'other-window)
(global-set-key "\C-x2" (lambda () (interactive)(split-window-vertically) (other-window 1)))
(global-set-key "\C-x3" (lambda () (interactive)(split-window-horizontally) (other-window 1)))
(add-hook 'solidity-mode-hook 'flymake-solidity-load)
(add-hook 'LaTeX-mode-hook 'hl-todo-mode)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-PDF-mode t)
(setq LaTeX-document-regexp "document\\|frame\\b")
(add-hook 'LaTeX-mode-hook (lambda () (TeX-global-PDF-mode t)))
(add-hook 'TeX-after-compilation-finished-functions
(defun my-TeX-after-compilation-finished-functions (file-name)
;; (message "compilation finished %s" file-name)
(let ((temp-file (format "%s_temp.pdf" (file-name-sans-extension file-name))))
(rename-file temp-file file-name t)
;; (call-process "open" nil 0 nil "somefile.pdf")
;; (browse-url-xdg-open (browse-url-file-url file-name))
)))
;; emacs.stackexchange.com/a/72102/18414
(add-to-list 'TeX-expand-list
'("%(mode)"
(lambda nil
(if TeX-interactive-mode ""
" -interaction=batchmode"))))
(defun my-run-latex ()
"Save all buffers and run LaTeX on the current master."
(interactive)
(let* ((apheleia-format-buffer)
(TeX-command-extra-options (format " -shell-escape -jobname=%s_temp" (TeX-master-file)))
(inhibit-message t)
(TeX-command-force "LaTeX")
(TeX-clean-confirm t)
(TeX-save-query nil)
(master (TeX-master-file))
(process (and (stringp master) (TeX-process master)))
(temp-file (expand-file-name (format "%s_temp.pdf" (TeX-master-file)))))
(TeX-save-document master)
(when (and (processp process)
(eq (process-status process) 'run))
(delete-process process))
(when (file-exists-p temp-file)
(delete-file temp-file))
(TeX-command-master)))
(add-hook 'LaTeX-mode-hook
(lambda ()
(when buffer-file-name
(add-hook 'after-save-hook
'my-run-latex
nil t))))
(setq TeX-command-force "LaTeX")
(setq TeX-clean-confirm t)
(defvar unfillable-envs '("figure" "tikzpicture" "table*" "tabular" "algorithm" "algorithmic" "longtable" "equation"))
(defvar font-latex-match-simple-exclude-list
'("%" "-" "," "/" "&" "#" "_" "`" "'" "^" "~" "=" "." "\"" "(" ")" "[" "]"))
;; create a function to check the environment first, then fill:
(defun my-filtered-fill ()
(unless (member (LaTeX-current-environment) unfillable-envs)
(do-auto-fill)))
(defun push-mark-no-activate ()
"Pushes `point' to `mark-ring' and does not activate the region
Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
(interactive)
(push-mark (point) t nil)
(message "Pushed mark to ring"))
;; https://emacs.stackexchange.com/questions/3458/how-to-switch-between-windows-quickly/3460?noredirect=1#comment93764_3460
(require 'beginend)
(dolist (mode (cons 'beginend-global-mode (mapcar #'cdr beginend-modes)))
(diminish mode))
(beginend-global-mode 1)
;; https://emacs.stackexchange.com/a/70379/18414
(apheleia-global-mode +1)
(with-eval-after-load 'apheleia
;; (setf (alist-get 'isort apheleia-formatters)
;; '("isort" "--stdout" "-"))
;; (setf (alist-get 'python-mode apheleia-mode-alist)
;; '(isort black))
(setf (alist-get 'python-mode apheleia-mode-alist)
'(black))
)
(diminish 'my-keys-minor-mode)
(diminish 'abbrev-mode)
(diminish 'anzu-mode)
(diminish 'subword-mode)
(diminish 'rainbow-mode)
(diminish 'modalka-mode)
(diminish 'company-mode)
(diminish 'highlight-parentheses-mode)
(diminish 'projectile-mode)
(diminish 'undo-tree-mode)
(diminish 'helm-mode)
(diminish 'wrap-mode)
(diminish 'visual-line-mode)
(diminish 'gcmh-mode)
(diminish 'describe-mode)
(diminish 'auto-fill-function)
(diminish 'flycheck-mode)
(diminish 'yas-minor-mode)
(diminish 'sphinx-doc-mode)
(defun app/LaTeX-mode-hook ()
(apheleia-mode -1))
(defun app/docker-compose-mode-hook ()
(apheleia-mode -1))
(defun app/mhtml-mode-hook ()
(apheleia-mode -1))
(add-hook 'LaTeX-mode-hook 'app/LaTeX-mode-hook)
(add-hook 'docker-compose-mode-hook 'app/docker-compose-mode-hook)
(add-hook 'mhtml-mode-hook 'app/mhtml-mode-hook)
(setq-default mode-line-format
(list "%e"
mode-line-front-space
'(:eval (when (file-remote-p default-directory)
(propertize "%1@"
'mouse-face 'mode-line-highlight
'help-echo (concat "remote: " default-directory))))
'(:eval (cond (buffer-read-only "%* ")
((buffer-modified-p) "❉ ")
(t " ")))
'(:eval (propertize "%12b" 'face 'mode-line-buffer-id 'help-echo default-directory))
'default-directory
`(vc-mode vc-mode)
" "
"("
'system-name
")"
" "
;; the current major mode for the buffer.
"["
'(:eval (propertize "%m" 'face 'font-lock-string-face
'help-echo buffer-file-coding-system))
"] "
" "
'(-3 "%p")
" "
;; line and column
"(" ;; '%02' to set to 2 chars at least; prevents flickering
(propertize "%02l" 'face 'font-lock-keyword-face) ","
(propertize "%02c" 'face 'font-lock-keyword-face)
") "
minor-mode-alist
"-%-" ; dashes sufficient to fill rest of modeline.
))
(defun flymake--transform-mode-line-format (ret)
"Change the output of `flymake--mode-line-format'."
(setf (seq-elt (car ret) 1) " FM")
ret)
(advice-add #'flymake--mode-line-format
:filter-return #'flymake--transform-mode-line-format)
(setq m/spam '(
"^ "
"^\\*Buffer List\\*$"
"^\\*WoMan-Log\\*$"
"^\\*Compile-Log\\*$"
"^\\*Flymake\\*$"
"^\\*tramp/.+\\*$"
"^\\*evil-marks\\*$"
"^\\*evil-registers\\*$"
"^\\*Shell Command Output\\*$"
"^\\*magit\\(-\\w+\\)?: .+$"
"^\\*irc\\..+\\*$"
"^\\*helm[- ].+\\*$"
"\\*helm-mode"
"\\*helm-mode.+"
"\\*Echo Area"
"\\*Minibuf"
"\\ *code-conversion-work\\*"
"org-src-fontification.+"
"\\*Org-Babel Error"))
(setq warning-minimum-level :emergency)
(add-to-list 'auto-mode-alist '("\\.env\\..*\\'" . dotenv-mode))
(defun flyspell-generic-textmode-verify ()
"Used for `flyspell-generic-check-word-predicate' in text modes."
;; (point) is next char after the word. Must check one char before.
(let ((f (get-text-property (- (point) 1) 'face)))
(not (memq f '(markdown-pre-face)))))
(setq flyspell-generic-check-word-predicate 'flyspell-generic-textmode-verify)
(setq flyspell-large-region 1)
(dolist (hook '(text-mode-hook))
(add-hook hook (lambda () (flyspell-mode 1))))
(dolist (hook '(change-log-mode-hook log-edit-mode-hook))
(add-hook hook (lambda () (flyspell-mode -1))))
(add-hook 'find-file-hook 'my-project-hook)
(defun my-project-hook ()
(when (string= (file-name-extension buffer-file-name) "tex")
(flyspell-buffer)))
(defun marker-is-point-p (marker)
"test if marker is current point"
(and (eq (marker-buffer marker) (current-buffer))
(= (marker-position marker) (point))))
(defun push-mark-maybe ()
"push mark onto `global-mark-ring' if mark head or tail is not current location"
(if (not global-mark-ring) (error "global-mark-ring empty")
(unless (or (marker-is-point-p (car global-mark-ring))
(marker-is-point-p (car (reverse global-mark-ring))))
(push-mark))))
(remove-hook 'flymake-diagnostic-functions 'flymake-proc-legacy-flymake)
(add-hook `yaml-mode-hook (lambda () (flyspell-mode -1)))
(defadvice do-auto-save (before no-message activate)
(ad-set-arg 0 t)) ;; disable auto-save message
(setq inhibit-startup-echo-area-message nil)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(add-to-list 'auto-mode-alist '("TODO_archive\\'" . org-mode))
(add-to-list 'auto-mode-alist '("TODO\\'" . org-mode))
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(setq org-log-done 'time) ;; https://emacs.stackexchange.com/a/60878/18414
(setq org-export-html-validation-link nil)
(setq org-html-validation-link nil)
(setq org-startup-with-inline-images t)
;; (setq org-agenda-span 'week)
(global-set-key (kbd "C-c a") 'org-agenda)
'(org-agenda-span 'day) ;; Show the daily agenda by default.
'(org-agenda-todo-ignore-scheduled 'future) ;; Hide tasks that are scheduled in the future.
;; Use "second" instead of "day" for time comparison.
;; It hides tasks with a scheduled time like "<2020-11-15 Sun 11:30>"
'(org-agenda-todo-ignore-time-comparison-use-seconds t)
;; Hide the deadline prewarning prior to scheduled date.
'(org-agenda-skip-deadline-prewarning-if-scheduled 'pre-scheduled)
;; Customized view for the daily workflow. (Command: "C-c a n")
'(org-agenda-custom-commands
'(("n" "Agenda / INTR / PROG / NEXT"
((agenda "" nil)
(todo "INTR" nil)
(todo "PROG" nil)
(todo "NEXT" nil))
nil)))
(setq org-todo-keywords
(quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
(sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING"))))
(setq org-todo-keyword-faces
(quote (;; ("TODO" :foreground "#ff5555" :weight bold)
("NEXT" :foreground "#bd93f9" :weight bold)
("DONE" :foreground "#50fa7b" :weight bold))))
(defun org-summary-todo (n-done n-not-done)
"Switch entry to DONE when all subentries are done, to TODO otherwise."
(let (org-log-done org-log-states) ; turn off logging
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
(add-to-list 'org-structure-template-alist '("py" . "src python"))
(add-to-list 'org-structure-template-alist '("tex" . "src latex"))
(add-to-list 'org-structure-template-alist '("go" . "src go"))
(add-to-list 'org-structure-template-alist '("yaml" . "src yaml"))
(add-to-list 'org-structure-template-alist '("json" . "src json"))
(add-to-list 'org-structure-template-alist '("mark" . "src markdown"))
(add-to-list 'org-structure-template-alist '("sh" . "src bash"))
(add-to-list 'org-structure-template-alist '("b" . "src bash"))
(setq org-babel-python-command "python3")
(setq org-completion-use-ido t)
'(indent-tabs-mode nil)
'(org-src-preserve-indentation nil)
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t)))
(defun org-archive-done-tasks ()
(interactive)
(org-map-entries
(lambda ()
(org-archive-subtree)
(setq org-map-continue-from (org-element-property :begin (org-element-at-point))))
"/DONE" 'file))
;; https://stackoverflow.com/a/27043756/2402577
;; (change 'tree back to 'file to operate over the entire file).
;; @alper changing "/DONE" to "/+DONE" fixes it for me
(defun insert-fixme ()
(interactive "*")
(insert comment-start "FIXME: "))
(defun insert-todo ()
(interactive "*")
(insert comment-start "TODO: "))
(define-key python-mode-map (kbd "C-c C-t") nil)
(define-key python-mode-map (kbd "C-c C-c") nil)
;;
(define-key prog-mode-map (kbd "C-c y") #'insert-fixme)
(define-key prog-mode-map (kbd "C-c C-y") #'insert-fixme)
(global-set-key (kbd "C-c C-y") 'insert-fixme)
;;
(define-key prog-mode-map (kbd "C-c t") #'insert-todo)
(define-key prog-mode-map (kbd "C-c C-t") #'insert-todo)
(global-set-key (kbd "C-c C-t") 'insert-todo)
;; link: https://stackoverflow.com/a/25942392/2402577
;; C-h f org-insert-todo-heading RET
;; C-h f org-insert-todo-heading-respect-content RET
(defun org-toggle-todo-and-fold ()
(interactive)
(save-excursion
(org-back-to-heading t) ;; Make sure command works even if point is
;; below target heading
(cond ((looking-at "\*+ TODO")
(org-todo "DONE")
(hide-subtree))
((looking-at "\*+ DONE")
(org-todo "TODO")
(hide-subtree))
(t (message "Can only toggle between TODO and DONE.")))))
(define-key org-mode-map (kbd "C-c C-c") 'org-toggle-todo-and-fold)
(define-key org-mode-map (kbd "C-c C-a") #'org-archive-done-tasks)
(define-key org-mode-map (kbd "C-c z") #'org-toggle-link-display)
(define-key org-mode-map (kbd "C-c C-z") #'org-toggle-link-display)
(define-key org-mode-map (kbd "C-c C-t") #'org-insert-todo-heading)
(define-key org-mode-map (kbd "C-x C-l") #'calendar-redraw)
(define-key org-mode-map (kbd "C-c C-e") #'nil)
;; https://emacs.stackexchange.com/a/76887/18414 ---------------------------------
(defun my/org-journal-new-entry (prefix &optional time)
(interactive "P")
(org-journal-new-entry (not prefix) time))
(with-eval-after-load "org-journal"
(define-key org-journal-mode-map (kbd "M-j") #'my/org-journal-new-entry))
(add-hook 'org-mode-hook (lambda ()
(local-set-key (kbd "M-j") 'my/org-journal-new-entry)))
(global-set-key (kbd "M-j") 'my/org-journal-new-entry)
;; ;; -----------------------------------------------------------------------------
(setq org-return-follows-link nil) ;; nil by default
(setq org-adapt-indentation nil)
(setq org-edit-src-content-indentation 0)
(defface my-code-face '((t :foreground "aquamarine")) "Your face.")
(font-lock-add-keywords 'org-mode '(("`+\\(.+?\\)`+" 1 'my-code-face)))
(setq org-ellipsis " ▾")
(add-hook 'org-mode-hook
(lambda ()
(font-lock-add-keywords
nil
'(("^-\\{3,\\}" 0 '(:foreground "#50fa7b" :weight bold))))))
(setq org-link-descriptive nil) ;; How to view URL of the links in org-mode
(tempo-define-template "inline-python" ; just some name for the template
'("#+begin_src python" n p n
"#+end_src")
"<p"
"Insert a script tag" ; documentation
'org-tempo-tags)
(defun org-todo-list-current-file (&optional arg)
"Like `org-todo-list', but using only the current buffer's file."
(interactive "P")
(let ((org-agenda-files (list (buffer-file-name (current-buffer)))))
(if (null (car org-agenda-files))
(error "%s is not visiting a file" (buffer-name (current-buffer)))
(org-todo-list arg))))
(global-set-key "\C-cr" 'org-capture)
(setq org-default-notes-file "~/tasks.org") ;; "~/Dropbox/notes/tasks.org"
(setq org-src-tab-acts-natively t)
(add-to-list 'auto-mode-alist '("\\.css$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.cfm$" . html-mode))
(defun _f () ;; insers f"{}" and move cursor two char left
(interactive)
(insert "f\"{}\"")
(backward-char)
(backward-char))
(defun break-point ()
(interactive)
(insert "breakpoint\(\) \# DEBUG"))
(defun python_main ()
(interactive)
(insert "if \_\_name\_\_ \=\= \"\_\_main\_\_\"\:"))
(defun doc-doc ()
(interactive)
(insert "\"\"\".\"\"\"")
(backward-char)
(backward-char)
(backward-char)
(backward-char))
(define-skeleton hello-world-skeleton
"Write a greeting"
"Type name of argument: "
"f\"{" str "}\"")
;; https://magit.vc/manual/magit/Resolving-Conflicts.html
(remove-hook 'flymake-diagnostic-functions 'flymake-proc-legacy-flymake)
;; https://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs
(defun my-minibuffer-setup-hook ()
(my-keys-minor-mode 0))
(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
(global-set-key (kbd "C-c p") 'flycheck-prev-error)
(global-set-key [(control q)] 'forward-word)
;; (global-set-key "\M-j" 'suspend-frame)
;; (global-set-key "\C-]" 'suspend-frame)
;; (define-key map (kbd "C-c C-j") 'suspend-frame)
(defun suspend-frame-alper () (interactive)
(save-all)
;; (recentf-save-list)
(suspend-frame))
(defun shift-text (distance)
(if (use-region-p)
(let ((mark (mark)))
(save-excursion
(indent-rigidly (region-beginning)
(region-end)
distance)
(push-mark mark t t)
(setq deactivate-mark nil)))
(indent-rigidly (line-beginning-position)
(line-end-position)
- distance)))
(defun shift-right (count)
(interactive "p")
(shift-text 4))
(defun shift-left (count)
(interactive "p")
(shift-text (- 4)))
(defun insert-seperator ()
(interactive "*")
(insert comment-start "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
;; (next-line)
(move-beginning-of-line 1))
(global-set-key (kbd "M-3") nil)
(defun mark-whole-word (&optional arg allow-extend)
(interactive "P\np")
(let ((num (prefix-numeric-value arg)))
(unless (eq last-command this-command)
(if (natnump num)
(skip-syntax-forward "\\s-")
(skip-syntax-backward "\\s-")))
(unless (or (eq last-command this-command)
(if (natnump num)
(looking-at "\\b")
(looking-back "\\b")))
(if (natnump num)
(left-word)
(right-word)))
(mark-word arg allow-extend)))
(global-set-key (kbd "C-x C-f") 'counsel-git-or-find-file)
(global-set-key "\C-h" 'delete-backward-char)
;; GLOBAL OVERWRITES ;;
(defvar my-keys-minor-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c v") smerge-basic-map)
(define-key map (kbd "C-c C-v") smerge-basic-map)
(define-key map (kbd "C-M-i") 'suspend-frame-alper)
(define-key map (kbd "M-p") 'hl-todo-previous)
(define-key map (kbd "M-n") 'hl-todo-next)
(define-key map (kbd "M-1") '_f)
(define-key map (kbd "M-2") 'sphinx-doc) ;; doc-doc
(define-key map (kbd "M-4") 'python_main)
(define-key map (kbd "M-DEL") 'backward-delete-word)
(define-key map (kbd "M-h") 'backward-delete-word)
(define-key map (kbd "C-c C-m") 'flycheck-or-norm-next-error)
(define-key map (kbd "C-l") 'backward-word)
(define-key map (kbd "C-q") 'forward-word)
(define-key map (kbd "C-c C-r") 'counsel-recentf)
(define-key map (kbd "C-c C-f") 'helm-find-files)
(define-key map (kbd "C-c f") 'helm-find-files)
(define-key map (kbd "C-x .") 'my-bottom)
(define-key map (kbd "C-x C-.") 'my-bottom)
(define-key map (kbd "C-c ;") 'comment-dwim-line)
(define-key map (kbd "\C-o") 'other-window)
(define-key map (kbd "<tab>") 'indent-for-tab-command)
(define-key map (kbd "C-c C-j") 'magit-status) ;; my-magit-status
(define-key map (kbd "C-c n") 'next-conflict)
(define-key map (kbd "C-c C-n") 'next-conflict)
(define-key map (kbd "C-c C-v n") 'next-conflict)
(define-key map (kbd "C-c C-d") 'consult-git-grep)
(define-key map (kbd "\C-x\ ,") 'beginning-of-buffer)
(define-key map (kbd "C-x C-,") 'beginning-of-buffer)
(define-key map (kbd "C-x C-u") 'nil)
(define-key map (kbd "C-h") 'delete-backward-char)
;; (define-key map (kbd "C-c C-u") 'insert-seperator)
;; (define-key map (kbd "C-c C-b") 'break-point)
;; (define-key map (kbd "C-c b") 'break-point)
;; (define-key map (kbd "C-x j") 'org-journal-new-entry)
;; (define-key map (kbd "C-c C-e") 'run_me)
;; (define-key map (kbd "C-c C-l") 'magit-log-buffer-file)
;; (define-key map (kbd "C-M-i") 'next-buffer)
;; (define-key map (kbd "C-x C-x") 'suspend-frame-alper)
;; (define-key map (kbd "C-c C-o") 'my-find-file)
;; (define-key map (kbd "M-x") 'execute-extended-command)
;; (define-key map (kbd "C-c C-p") 'flycheck-or-norm-previous-error)
;; (define-key map (kbd "C-c C-e") 'shell-command)
map))
(define-key python-mode-map (kbd "C-c C-b") 'break-point)
(define-key python-mode-map (kbd "C-c b") 'break-point)
(define-key org-mode-map (kbd "C-c C-b") 'org-toggle-checkbox)
(define-key org-mode-map (kbd "C-c C-b") #'org-toggle-checkbox)
(global-set-key (kbd "C-x DEL") 'mark-whole-buffer)
(global-set-key (kbd "C-x C-l") 'recenter)
;; (global-set-key "\C-x\C-f" 'counsel-find-file)
(defun dired-open-file ()
"In dired, open the file named on this line."
(interactive)
(let* ((file (dired-get-filename nil t)))
(call-process "xdg-open" nil 0 nil file)))
(define-minor-mode my-keys-minor-mode
"A minor mode so that my key settings override annoying major modes."
:init-value t
:lighter " my-keys")
(my-keys-minor-mode 1)
(global-set-key (kbd "C-c l") 'magit-log-buffer-file)
(add-to-list 'ibuffer-never-show-predicates "__init__.py")
(variable-pitch-mode t)
(setq 1on1-minibuffer-frame-font
"-*-Lucida Console-normal-r-*-*-14-112-96-96-c-*-iso8859-1")
(defadvice py-execute-buffer (after advice-delete-output-window activate)
(delete-windows-on "*Python Output*"))
(global-set-key "\C-x\C-w" 'mark-whole-word)
(defvar python--pdb-breakpoint-string "import pdb; pdb.set_trace() ## DEBUG ##"
"Python breakpoint string used by `python-insert-breakpoint'")
(defadvice compile (before ad-compile-smart activate)
"Advises `compile' so it sets the argument COMINT to t
if breakpoints are present in `python-mode' files"
(when (derived-mode-p major-mode 'python-mode)
(save-excursion
(save-match-data
(goto-char (point-min))
(if (re-search-forward (concat "^\\s-*" python--pdb-breakpoint-string "$")
(point-max) t)
;; set COMINT argument to `t'.
(ad-set-arg 1 t))))))
(defun my-magit-status ()
"Don't split window."
(interactive)
(setq split-height-threshold nil)
(setq split-width-threshold 0)
(call-interactively 'magit-status))
(defun indent-buffer ()
"Indents an entire buffer using the default intenting scheme."
(interactive)
(point-to-register 'o)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max))
(jump-to-register 'o))
(global-set-key "\C-x\\" 'indent-buffer)
(setq ibuffer-expert t) ;; don't ask for confirmation to delete marked buffers
;; C-h m to find all the things you can do in Man-mode
(define-key Man-mode-map "q" 'my-kill-emacs)
(define-key Man-mode-map "Q" 'my-kill-emacs)
;; maple: https://github.com/honmaple/emacs-maple-minibuffer
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region (point-min) (point-max))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
(global-set-key (kbd "C-M-/") 'my-expand-file-name-at-point)
(defun my-expand-file-name-at-point ()
"Use hippie-expand to expand the filename"
(interactive)
(let ((hippie-expand-try-functions-list '(try-complete-file-name-partially try-complete-file-name)))
(call-interactively 'hippie-expand)))
(defun really-kill-emacs ()
"Like `kill-emacs', but ignores `kill-emacs-hook'."
(interactive)
(let (kill-emacs-hook)
(kill-emacs)))
(electric-indent-mode +1)
(defvar untabify-this-buffer)
(defun untabify-all ()
"Untabify the current buffer, unless `untabify-this-buffer' is nil."
(and untabify-this-buffer (untabify (point-min) (point-max))))
(define-minor-mode untabify-mode
"Untabify buffer on save." nil " untab" nil
(make-variable-buffer-local 'untabify-this-buffer)
(setq untabify-this-buffer (not (derived-mode-p 'makefile-mode)))
(add-hook 'before-save-hook #'untabify-all))
(add-hook 'prog-mode-hook 'untabify-mode)
;; Better unique buffer names for files with the same base name.
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; (advice-add 'compilation-filter :around #'my/advice-compilation-filter)
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
"Prevent annoying \"Active processes exist\" query when you quit Emacs."
(cl-letf (((symbol-function #'process-list) (lambda ())))
ad-do-it))
(defun my-kill-emacs ()
"save some buffers, then exit unconditionally"
(interactive)
(save-all)
;; (save-some-buffers nil t)
(save-buffers-kill-terminal))
(global-set-key (kbd "C-x C-c") 'my-kill-emacs)
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups_q"))))
(defvar --backup-directory (concat user-emacs-directory "backups"))
(if (not (file-exists-p --backup-directory))
(make-directory --backup-directory t))
(setq backup-directory-alist `(("." . ,--backup-directory)))
(setq vc-make-backup-files t
backup-by-copying t ; don't clobber symlinks
version-control t ; version numbers for backup files
delete-old-versions t ; delete excess backup files silently
auto-save-default t ; auto-save every buffer that visits a file
auto-save-timeout 20 ; number of seconds idle time before auto-save (default: 30)
auto-save-interval 200 ; number of keystrokes between auto-saves (default: 300)
kept-new-versions 10 ; Number of newest versions to keep.
kept-old-versions 10 ; Number of oldest versions to keep.
delete-by-moving-to-trash t
backup-directory-alist '(("" . "~/.emacs.d/backup")))
;; kept-old-versions 0 ;; Number of oldest versions to keep.
(add-to-list 'term-file-aliases
'("st-256color" . "xterm-256color"))
(defun git-log-file ()
"Display a log of changes to the marked file(s)."
(interactive)
(let* ((files (git-marked-files))
(buffer (apply #'git-run-command-buffer "*git-log*" "git-rev-list" \
"--pretty" "HEAD" "--" (git-get-filenames files)))) (with-current-buffer buffer
; (git-log-mode) FIXME: implement log mode
(goto-char (point-min))
(setq buffer-read-only t))
(display-buffer buffer)))
(defun python-fn (code)
(let* ((temporary-file-directory ".")
(tmpfile (make-temp-file "py-" nil ".py")))
(with-temp-file tmpfile
(insert code))
(car (split-string (shell-command-to-string (format "python %s" tmpfile)) "\n$"))))
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region (point-min) (point-max))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
(add-hook 'shell-mode-hook (lambda () (goto-address-mode )))
(setenv "ESHELL" (expand-file-name "~/.emacs_config/scripts/eshell"))
(require 'exec-path-from-shell) ;; if not using the ELPA package
(exec-path-from-shell-initialize)
(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(require 'ansi-color) ;; for `ansi-color-apply-on-region'
(require 'subr-x) ;; for `string-trim-right'
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(require 'eshell)
(require 'em-smart)
(setq eshell-where-to-jump 'begin)
(setq eshell-review-quick-commands nil)
(setq eshell-smart-space-goes-to-end t)
(defun display-ansi-colors ()
(interactive)
(ansi-color-apply-on-region (point-min) (point-max)))
(defun your-eshell-command (command)
"Execute eshell COMMAND and display output in the echo area."
(interactive (list (read-shell-command "Eshell command: ")))
(message "%s" (string-trim-right (eshell-command-result command))))
(defun your-ansi-color-apply (s)
"Like `ansi-color-apply' but use `face' instead of `font-lock-face'."
(with-temp-buffer
(insert s)
(let ((ansi-color-apply-face-function
(lambda (beg end face)
(when face
(put-text-property beg end 'face face)))))
(ansi-color-apply-on-region (point-min) (point-max)))
(buffer-string)))
(add-hook 'dired-mode-hook 'auto-revert-mode) ;; auto refresh dired when file changes
(setq auto-revert-verbose nil) ;; https://emacs.stackexchange.com/q/68652/18414 ;; (setq auto-revert-use-notify nil)
(defun my-revert-buffer-noconfirm ()
"Call `revert-buffer' with the NOCONFIRM argument set."
(interactive)
(revert-buffer nil t))
;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive)
(revert-buffer :ignore-auto :noconfirm))
;; (setq backup-directory-alist '(("" . "~/.emacs.d/backup/per-save")))
(defun force-backup-of-buffer ()
;; Make a special "per session" backup at the first save of each
;; emacs session.
(when (not buffer-backed-up)
;; Override the default parameters for per-session backups.
(let ((backup-directory-alist '(("" . "~/.emacs.d/backup/per-session")))
(kept-new-versions 3))
(backup-buffer)))
;; Make a "per save" backup on each save. The first save results in
;; both a per-session and a per-save backup, to keep the numbering
;; of per-save backups consistent.
(let ((buffer-backed-up nil))
(backup-buffer)))
(add-hook 'before-save-hook 'force-backup-of-buffer)
(defun le::save-buffer-force-backup (arg)
(interactive "P")
(if (consp arg)
(save-buffer)
(save-buffer 16)))
(global-set-key [remap save-buffer] 'le::save-buffer-force-backup)
(defun markdown-flyspell-check-word-p ()
"Return t if `flyspell' should check word just before point.
Used for `flyspell-generic-check-word-predicate'."
(save-excursion
(goto-char (1- (point)))
(not (or (markdown-code-block-at-point-p)
(markdown-inline-code-at-point-p)
(markdown-in-comment-p)
(let ((faces (get-text-property (point) 'face)))
(if (listp faces)
(or (memq 'markdown-reference-face faces)
(memq 'markdown-markup-face faces)
(memq 'markdown-url-face faces))
(memq faces '(markdown-reference-face
markdown-markup-face
markdown-url-face))))))))
(add-hook 'git-commit-mode-hook #'display-fill-column-indicator-mode) ;; ruler
(add-hook 'markdown-mode-hook
(lambda ()
(when buffer-file-name
(add-hook 'after-save-hook
'check-parens
nil t))))
;; from https://github.com/abo-abo/swiper/issues/1068
(defun my-ivy-with-thing-at-point (cmd &optional dir)
"Wrap a call to CMD with setting "
(let ((ivy-initial-inputs-alist
(list
(cons cmd (thing-at-point 'symbol)))))
(funcall cmd nil dir)))
(defun my-counsel-ag-from-here (&optional dir)
"Start ag but from the directory the file is in (otherwise I would
be using git-grep)."
(interactive "D")
(my-ivy-with-thing-at-point
'counsel-ag
(or dir (file-name-directory (buffer-file-name)))))
;; https://github.com/joaotavora/yasnippet
(require 'yasnippet)
(yas-global-mode 1)
(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "C-c C-i") 'yas-expand)
(defvar yas-keymap
(let ((map (make-sparse-keymap)))
(define-key map (kbd "TAB") (yas-filtered-definition 'yas-next-field-or-maybe-expand))))
(setq lisp-indent-function 'common-lisp-indent-function)
(setq history-length 100)
(put 'minibuffer-history 'history-length 50)
(put 'evil-ex-history 'history-length 50)
(put 'kill-ring 'history-length 25)
;; https://emacs.stackexchange.com/a/63665/18414
;; define environments we don't want to autofill:
(global-set-key (kbd "C-c q") 'auto-fill-mode)
;; (defun goto-def-or-rgrep ()
;; "Go to definition of thing at point or do an rgrep in project if that fails"
;; (interactive)
;; (condition-case nil (rope-goto-definition)
;; (error (rope-goto-definition (thing-at-point 'symbol)))))
(global-set-key "\C-x\C-j" 'xref-find-definitions)
(global-set-key "\C-x\C-k" 'xref-pop-marker-stack)
(defun disable-lsp-conn-msg-advice (func &rest r)
(unless (string-prefix-p "Connected to" (car r))
(apply func r)))
(advice-add 'lsp--info :around #'disable-lsp-conn-msg-advice)
(global-set-key (kbd "C-c C-k") 'company-complete)
;; (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(setq custom-file "~/.emacs.d/config/custom.el") (load-file custom-file)
;; https://emacs.stackexchange.com/a/64377/18414
(with-eval-after-load 'ibuf-ext
(dolist (name '("*lsp-log*" "*pyls::stderr*" "*Disabled Command*"))
(push (regexp-quote name) ibuffer-never-show-predicates)))
(require 'pyvenv) ;; https://github.com/jorgenschaefer/pyvenv
(pyvenv-activate "~/venv/")
(font-lock-add-keywords nil '(("\\([\{\}\\[\]\(\)]+\\)" 1 font-lock-keyword-face prepend)))
(setq python-indent-guess-indent-offset t)
(setq python-indent-guess-indent-offset-verbose nil)
(defun ask-user-about-supersession-threat (fn)
"blatantly ignore files that changed on disk"
)
(defun ask-user-about-lock (file opponent)
"always grab lock"
t)
(setq revert-without-query '(".*"))
(defun smart-line-beginning ()
"Move point to the beginning of text on the current line; if that is already
the current position of point, then move it to the beginning of the line."
(interactive)
(let ((pt (point)))
(back-to-indentation) ;; (beginning-of-line-text)
(when (eq pt (point))
(beginning-of-line))))
(global-set-key "\C-a" 'smart-line-beginning)
;; (setq-default toggle-case-fold-search 0) ; Turn Off Smart Case Sensitivity
(defun my-find-files ()
(interactive)
(setq case-fold-search nil)
(message "press t to toggle mark for all files found && Press Q for Query-Replace in Files...")
(find-dired (vc-git-root (buffer-file-name)) "-type f \\( -name '*.py' -o -name '*.sol' -o -name '*.org' \\) -not \\( -path './.eggs/*' -prune \\) ! -name '__init__.py' ! -name 'flycheck_\\*.py' -not \\( -path './build/*' -prune \\)"))
(global-set-key (kbd "M-z") 'my-find-files)
(defun backward-delete-char-stop-at-read-only (n &optional killflag)
"Do as `backward-delete-char' but stop at read-only text."
(interactive "p\nP")
(unless (or (get-text-property (point) 'read-only)
(eq (point) (point-min))
(get-text-property (1- (point)) 'read-only))
(setq n (min (- (point) (point-min)) n))
(setq n (- (point) (previous-single-property-change (point) 'read-only nil (- (point) n))))
(backward-delete-char n killflag)))
(define-key minibuffer-local-map (kbd "C-h") #'backward-delete-char-stop-at-read-only)
(define-key minibuffer-local-map (kbd "C-n") #'next-line-or-history-element)
(define-key minibuffer-local-map (kbd "C-p") #'previous-line-or-history-element)
(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-c C-b") 'break-point)
(global-flycheck-mode 1)
;; https://emacs.stackexchange.com/a/18162/18414
(defun remove-extra-blank-lines ()
"replace multiple blank lines with a single one"
(interactive)
(setq orig (point))
(goto-char (point-min))
(while (re-search-forward "^\n+" nil t)
(replace-match "\n")
(forward-char 1))
(goto-char orig))
;; https://emacs.stackexchange.com/questions/315/using-desktop-for-basic-project-management
(setq desktop-globals-to-save ;; ~/.emacs.d/.emacs.desktop
(append '((comint-input-ring . 50)
(compile-history . 30)
desktop-missing-file-warning
(dired-regexp-history . 20)
(extended-command-history . 30)
(face-name-history . 20)
(file-name-history . 100)
(grep-find-history . 30)
(grep-history . 30)
(ido-buffer-history . 100)
(ido-last-directory-list . 100)
(ido-work-directory-list . 100)
(ido-work-file-list . 100)
(magit-read-rev-history . 50)
(minibuffer-history . 50)
(org-clock-history . 50)
(org-refile-history . 50)
(org-tags-history . 50)
(query-replace-history . 60)
(read-expression-history . 60)
(regexp-history . 60)
(regexp-search-ring . 20)
register-alist
(search-ring . 20)
(shell-command-history . 50)
tags-file-name
tags-table-list)))
(setq python-font-lock-keywords-maximum-decoration
(append python-font-lock-keywords-maximum-decoration
'(("f\\(['\"]\\{1,3\\}\\)\\(.+?\\)\\1"
("{[^}]*?}"
(progn (goto-char (match-beginning 0)) (match-end 0))
(goto-char (match-end 0))
(0 font-lock-variable-name-face t))))))
(defun my-set-shell ()
(interactive)
(sh-set-shell "sh"))
(defun my-shell-mode-faces () ;; https://emacs.stackexchange.com/a/67922/18414
(face-remap-add-relative 'font-lock-variable-name-face '(:foreground "LightGoldenrod" :weight bold)))
(add-hook 'sh-mode-hook 'my-shell-mode-faces)
(add-hook 'sh-mode-hook #'lsp)
(add-hook 'sh-mode-hook 'my-set-shell)
(defun your-shell-command (command)
"A simplified `shell-command' to support color."
(interactive (list (read-shell-command "Shell command: ")))
(message "%s"
(string-trim-right
(your-ansi-color-apply
(shell-command-to-string command)))))
(defun run_me ()
(interactive) ;; https://emacs.stackexchange.com/a/61667/18414
(save-all)
(your-shell-command (format "%s" buffer-file-name)))
(defun run_me_python ()
(interactive) ;; https://emacs.stackexchange.com/a/61667/18414
(save-all)
(your-shell-command (format "python %s" buffer-file-name)))
(defun run_me_bash ()
(interactive)
(save-all)
(your-shell-command (format "bash %s" buffer-file-name)))
(define-key python-mode-map (kbd "C-c C-e") 'run_me_python)
(with-eval-after-load "sh-script"
(define-key sh-mode-map (kbd "C-c C-e") 'run_me_bash))
(setq sh-basic-offset 4
sh-indentation 4)
(setq auto-mode-alist
(cl-union auto-mode-alist
'(("\\slurm.conf\\'" . slurm-script-mode)
("\\slurmdbd.conf\\'" . slurm-script-mode)
("\\.bash_profile\\'" . sh-mode)
("\\.ssh_addresses\\'" . sh-mode)
("\\.pdbrc\\'" . sh-mode)
("\\.aliases\\'" . sh-mode)
("\\pre-push\\'" . sh-mode)
("\\pre-push.sample\\'" . sh-mode)
("\\pre-commit\\'" . sh-mode)
("\\pre-commit.sample\\'" . sh-mode)
("\\.tmux.conf\\'" . sh-mode)
("\\.zpath\\'" . sh-mode)
("\\.bashrc\\'" . sh-mode)
("\\.inputrc\\'" . sh-mode)
("\\.profile\\'" . sh-mode)
("\\.zprofile\\'" . sh-mode)
("inputrc\\'" . sh-mode)
("ssh_addresses\\'" . sh-mode)
("aliases\\'" . sh-mode)
("aliases_kama\\'" . sh-mode)
("profile\\'" . sh-mode)
("bashrc\\'" . sh-mode)
("bash_profile\\'" . sh-mode)
("zprofile\\'" . sh-mode)
("bashrc\\'" . sh-mode)
("zshrc\\'" . sh-mode)
("\\kill_e\\'" . sh-mode)
("\\.zshrc\\'" . sh-mode)
("\\.zsh_history\\'" . sh-mode)
("\\.bash_history\\'" . sh-mode)
)))
(defun alt-exchange-point-and-mark (&optional arg)
(interactive "P")
(exchange-point-and-mark (not arg))
(recenter-top-bottom))
(global-set-key (kbd "C-x C-m") 'alt-exchange-point-and-mark)
(global-set-key (kbd "C-x C-x") 'nil)
(global-set-key "\M-," 'my-counsel-git-grep)
(global-set-key (kbd "C-x C-t") 'toggle-truncate-lines)
;; (global-set-key (kbd "C-x C-x") 'alt-exchange-point-and-mark)
;; FREE VARIABLES
(global-set-key (kbd "M-c") 'nil)
(global-set-key "\C-x\ u" 'nil)
(global-set-key (kbd "C-x C-u") 'nil)
(define-key python-mode-map (kbd "C-x C-u") nil)
(define-key python-mode-map (kbd "C-c C-l") 'nil)
(define-key python-mode-map (kbd "C-c C-p") 'nil)
(global-set-key (kbd "C-x ;") 'nil)
;; (define-key python-mode-map (kbd "M-j") 'nil)
;; (global-set-key (kbd "C-x C-m") 'nil)
;; (global-set-key (kbd "C-h SPC") 'helm-all-mark-rings)
;; counsel-mark-ring
;; you can keep pressing C-SPC after the first invocation of C-u C-SPC to jump
;; to previous locations stored in the mark ring.
(flyspell-mode 1)
(setq set-mark-command-repeat-pop t)
(setq ispell-dictionary "english" ; Default dictionary. To change do M-x ispell-change-dictionary RET
ispell-local-dictionary "en_US"
flyspell-issue-message-flag nil
ispell-program-name "hunspell" ;; "aspell" or nil
ispell-extra-args '("--sug-mode=ultra"))
(add-hook 'lsp-signature-mode-hook #'lsp-signature-hook-function)
(setq rg-src-preserve-indentation nil)
(defadvice recentf-cleanup
(around no-message activate)
"suppress the output from message() to minibuffer"
(flet ((message (format-string &rest args)
(eval `(format ,format-string ,@args))))
ad-do-it))
(setq recentf-max-saved-items 50)
(setq recentf-max-menu-items 50)
(setq recentf-exclude '("^/var/folders\\.*"
"[/\\]\\.elpa/"
"COMMIT_EDITMSG\\'"
"bookmark-default.el"
".*-autoloads\\.el\\'"
"\\.recentf\\'"
"*\\.el\\'"
"emacs_q"
"kama_emacs"
"**Ibuffer*\\"
"\\*Compile-Log*\\"
"\\NEWS\\'"
"\\.zshrc\\'"
"\\.zshenv\\'"
"\\package.list\\'"
"\\.aliases\\'"
"\\.zprofile\\'"
"\\.bashrc\\'"
"\\.emacs\\'"
"\\TODO_archive\\'"
))
(run-at-time nil (* 5 60) 'recentf-save-list)
(add-hook 'delete-terminal-functions (lambda (terminal) (recentf-save-list)))
(recentf-load-list)
(setq recentf-save-file (recentf-expand-file-name "~/.emacs.d/.recentf"))
(setq recentf-auto-cleanup 10)
(recentf-mode 1)
;; (with-eval-after-load 'find-file-in-project
;; (setq-default ffip-prune-patterns (add-to-list 'ffip-prune-patterns "*/.mypy_cache")) )
(defun my-counsel-git-grep ()
(interactive)
(my-ivy-with-thing-at-point
'counsel-git-grep))
(defvar my-mode-map (make-sparse-keymap)
"Keymap for `my-mode'.")
(define-minor-mode my-mode ;; ###autoload
"A minor mode so that my key settings override annoying major modes."
;; If init-value is not set to t, this mode does not get enabled in
;; `fundamental-mode' buffers even after doing \"(global-my-mode 1)\".
;; More info: http://emacs.stackexchange.com/q/16693/115
:init-value t
:lighter " my-mode"
:keymap my-mode-map)
;; Change the user-emacs-directory to keep unwanted things out of ~/.emacs.d
(setq user-emacs-directory (expand-file-name "~/.cache/emacs/")
url-history-file (expand-file-name "url/history" user-emacs-directory))
;; Use no-littering to automatically set common paths to the new user-emacs-directory
(use-package no-littering ;; https://config.daviwil.com/emacs#keep-emacsd-clean
:ensure t)
(define-globalized-minor-mode global-my-mode my-mode my-mode)
;; https://github.com/jwiegley/use-package/blob/master/bind-key.el
;; The keymaps in `emulation-mode-map-alists' take precedence over
;; `minor-mode-map-alist'
(add-to-list 'emulation-mode-map-alists `((my-mode . ,my-mode-map)))
;; Turn off the minor mode in the minibuffer
(defun turn-off-my-mode ()
"Turn off my-mode."
(my-mode -1))
(add-hook 'minibuffer-setup-hook #'turn-off-my-mode)
(provide 'my-mode)
(defhydra python-indent (my-mode-map "C-c")
"Adjust python indentation."
(">" python-indent-shift-right "right")
("<" python-indent-shift-left "left"))
(defadvice show-paren-function
(around show-paren-closing-before
activate compile)
(if (eq (syntax-class (syntax-after (point))) 5)
(save-excursion
(forward-char)
ad-do-it)
ad-do-it))
(show-paren-mode t)
(setq show-paren-style 'parenthesis)
(setq show-paren-delay 0)
(require 'paren)
(require 'rainbow-delimiters)
(add-hook 'prog-mode-hook (lambda ()
(unless (eq major-mode 'sh-mode)
(rainbow-delimiters-mode))))
;; (set-face-background 'show-paren-match (face-background 'default))
;; (set-face-foreground 'show-paren-match "#def")
;; (setq show-paren-style 'expression)
;; (set-face-attribute 'show-paren-match nil :weight 'extra-bold)
(defun my-save-word ()
(interactive)
(let ((current-location (point))
(word (flyspell-get-word)))
(when (consp word)
(flyspell-do-correct 'save nil (car word) current-location (cadr word) (caddr word) current-location))))
(defun my-LaTeX-parse-block-after-insert-environment (env _b _e)
"Parse MMM block after inserting a markdown environment.
`mmm-parse-block' is only called when ENV is \"markdown\"."
(when (string-equal env "markdown")
(mmm-parse-block 3)))
(defun my_undefined ()
"Beep to tell the user this binding is undefined."
(declare (completion ignore))
(interactive)
(ding)
(if defining-kbd-macro
(error "" (key-description (this-single-command-keys)))
(message "" (key-description (this-single-command-keys))))
(force-mode-line-update)
;; If this is a down-mouse event, don't reset prefix-arg;
;; pass it to the command run by the up event.
(setq prefix-arg
(when (memq 'down (event-modifiers last-command-event))
current-prefix-arg)))
(add-hook 'LaTeX-after-insert-env-hook #'my-LaTeX-parse-block-after-insert-environment)
(global-set-key (kbd "M-;") 'ispell-word)
(require 'helm) ;; -----------------------------------------------------
(helm-autoresize-mode 1)
(customize-set-variable 'helm-ff-lynx-style-map t)
;; (global-set-key (kbd "M-;") 'helm-flyspell-correct)
(define-key helm-map (kbd "<backtab>") 'helm-previous-line)
(define-key helm-map (kbd "<right>") 'helm-execute-persistent-action)
(define-key helm-map (kbd "<left>") 'helm-execute-persistent-action)
(define-key helm-map (kbd "C-z") #'helm-select-action)
(define-key helm-map (kbd "TAB") 'my_undefined)
(define-key helm-map (kbd "<tab>") 'my_undefined)
;; (setq helm-autoresize-min-height 30)
;; (setq helm-autoresize-max-height 30)
;; ---------------------------------------------------------------------
;; See https://github.com/flycheck/flycheck/issues/1762
(defvar-local my/flycheck-local-cache nil)
(defun my/flycheck-checker-get (fn checker property)
(or (alist-get property (alist-get checker my/flycheck-local-cache))
(funcall fn checker property)))
(advice-add 'flycheck-checker-get :around 'my/flycheck-checker-get)
(defun no-msg (function)
(let ((inhibit-message t))
(funcall function)))
(advice-add 'recentf-save-list :around 'no-msg)
(defun my-clean-frames-and-buffers () ;; kill all buffer
"Kills all unmodified buffers and closes all but the selected frame."
(interactive)
(save-window-excursion
(dolist (buffer (buffer-list))
(and (buffer-live-p buffer)
(not (buffer-modified-p buffer))
(kill-buffer buffer))))
(delete-other-frames))
(add-to-list 'ispell-skip-region-alist '(":\\(PROPERTIES\\|LOGBOOK\\):" . ":END:"))
(add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
(add-to-list 'ispell-skip-region-alist '("#\\+begin_src" . "#\\+end_src"))
(add-to-list 'ispell-skip-region-alist '("href{" . "}")) ;; ? ;; https://superuser.com/a/345461/723632
(setq org-tag-alist '(("@work" . ?w) ("@help" . ?h) ("cmd" . ?c)))
;; NO spell check for embedded snippets
(defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
(let* ((rlt ad-return-value)
(begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\|example\\|quote\\)")
(end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\|example\\|quote\\)")
(case-fold-search t)
b e)
(when ad-return-value
(save-excursion
(setq b (re-search-backward begin-regexp nil t))
(if b (setq e (re-search-forward end-regexp nil t))))
(if (and b e (< (point) e)) (setq rlt nil)))
(setq ad-return-value rlt)))
(global-undo-tree-mode t) ;; https://emacs.stackexchange.com/questions/59942/is-it-possible-suppress-save-message-for-undo-tree
(setq undo-tree-auto-save-history t)
(setq undo-tree-enable-undo-in-region nil)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))
(defun undo-tree-visualizer-update-linum (&rest args)
(linum-update undo-tree-visualizer-parent-buffer))
(advice-add 'undo-tree-visualize-undo :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-redo :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-undo-to-x :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-redo-to-x :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualizer-mouse-set :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualizer-set :after #'undo-tree-visualizer-update-linum)
(setq undo-tree-auto-save-history t)
(global-set-key (kbd "C-\-") 'undo-tree-undo)
(global-set-key (kbd "C-x C-_") 'undo-tree-redo)
(global-set-key "\C-x\C-v" 'undo-tree-visualize)
(setenv "PATH" (concat (getenv "PATH") ":/Library/TeX/texbin/"))
(setq exec-path (append exec-path '("/Library/TeX/texbin/")))
(add-hook 'smerge-mode-hook (lambda () (flycheck-mode -1)))
(setq company-clang-insert-arguments nil)
(defun kill-all-buffers ()
"Close all buffers."
(interactive)
;; (maybe-unset-buffer-modified)
(delete-other-windows)
(save-some-buffers)
(let
((kill-buffer-query-functions '())
(lsp-restart 'ignore))
(mapc 'kill-buffer (buffer-list))))
(bind-key "C-c K" #'kill-all-buffers)
(setq diff-font-lock-syntax 'hunk-only)
(advice-add 'sh-set-shell :around
(lambda (orig-fun &rest args)
(cl-letf (((symbol-function 'message) #'ignore))
(apply orig-fun args))))
(define-key python-mode-map (kbd "C-c C-o") #'pyimport-insert-missing) ;; https://github.com/Wilfred/pyimport
;; (define-key python-mode-map (kbd "M-d") 'python-black)
(define-key python-mode-map (kbd "M-d") 'python-black-buffer)
;; (use-package python-black
;; :demand t
;; :after python
;; ;; :hook (python-mode . python-black-on-save-mode-enable-dwim))
;; )
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(define-derived-mode my-git-commit-mode org-mode "Git Commit"
(git-commit-mode 1))
(add-to-list 'auto-mode-alist
'("/\\.git/MERGE_MSG\\'" . git-commit-mode))
(add-to-list 'auto-mode-alist
'("/\\.git/COMMIT_EDITMSG\\'" . git-commit-mode))
(add-to-list 'auto-mode-alist
'("/\\.git/commit-msg\\'" . git-commit-mode))
(setq git-commit-major-mode 'my-git-commit-mode)
(defun _commit ()
(interactive)
(delete-trailing-whitespace))
(add-hook 'git-commit-mode-hook (lambda () (local-set-key (kbd "C-x C-s") '_commit)))
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(defun ansi-color-apply-on-region-int (beg end)
"interactive version of func"
(interactive "r")
(ansi-color-apply-on-region beg end))
(define-minor-mode ansi-color-mode
"..." ;; https://emacs.stackexchange.com/a/69939/18414
nil nil nil
(ansi-color-apply-on-region 1 (buffer-size)))
;; LATEX -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(defun xxx ()
(interactive)
(goto-char (point-min))
(while (re-search-forward "\\\\begin{verbatim}" nil 1)
(progn
(replace-regexp "%" "@@@@@PERCENT@@@@@" nil (point)
(save-excursion
(progn (re-search-forward "\\\\end{verbatim}" nil 1) (point))))))
(goto-char (point-min))
(while (re-search-forward "\\\\verb|" nil 1)
(progn
(replace-regexp "%" "@@@@@PERCENT@@@@@" nil (point)
(save-excursion
(progn (re-search-forward "|" nil 1) (point))))))
(goto-char (point-min))
(replace-regexp "%.*\\(\n\\|$\\)" "" nil nil)
(goto-char (point-min))
(replace-regexp "@@@@@PERCENT@@@@@" "%" nil nil))
(defun tabular-magic () ;; https://tex.stackexchange.com/a/557976/127048
(interactive)
(unless (string= (LaTeX-current-environment) "document")
(let ((s (make-marker))
(e (make-marker)))
(set-marker s (save-excursion
(LaTeX-find-matching-begin)
(forward-line)
(point)))
(set-marker e (save-excursion
(LaTeX-find-matching-end)
(forward-line -1)
(end-of-line)
(point)))
(whitespace-cleanup-region s e)
(align-regexp s e "\\(\\s-*\\)&" 1 1 t)
(align-regexp s e "\\(\\s-*\\)\\\\\\\\")
(set-marker s nil)
(set-marker e nil))))
(add-hook 'LaTeX-mode-hook
(lambda () ;; Choose a key binding for LaTeX mode:
(local-set-key (kbd "C-c e") #'tabular-magic)))
(add-hook 'LaTeX-mode-hook (lambda () ;; Choose a key binding for LaTeX mode:
(local-set-key (kbd "C-c C-e") 'tabular-magic)))
(defun my-latex-mode-hook ()
(setq fill-column 180)
;; (auto-fill-mode t)
)
(add-hook 'LaTeX-mode-hook #'my-latex-mode-hook)
;; Modified from http://pleasefindattached.blogspot.com/2011/12/emacsauctex-sentence-fill-greatly.html
(defadvice LaTeX-fill-region-as-paragraph (around LaTeX-sentence-filling)
"Start each sentence on a new line."
(let ((from (ad-get-arg 0))
(to-marker (set-marker (make-marker) (ad-get-arg 1)))
tmp-end)
(while (< from (marker-position to-marker))
(forward-sentence)
;; might have gone beyond to-marker---use whichever is smaller:
(ad-set-arg 1 (setq tmp-end (min (point) (marker-position to-marker))))
ad-do-it
(ad-set-arg 0 (setq from (point)))
(unless (or (looking-back "^\\s *")
(looking-at "\\s *$"))
(LaTeX-newline)))
(set-marker to-marker nil)))
(ad-activate 'LaTeX-fill-region-as-paragraph)
(defun bib-mode-hook ()
(setq fill-column 100))
(add-hook 'LaTeX-mode-hook (lambda ()
(TeX-fold-mode 1)))
(defun flyspell-ignore-tex ()
(interactive)
(set (make-variable-buffer-local 'ispell-parser) 'tex))
;; avoid performance issues in files with very long lines.
(global-so-long-mode 1)
(setq-default bidi-display-reordering nil)
(setq-default bidi-inhibit-bpa t)
(add-hook 'bibtex-mode-hook #'bib-mode-hook)
(setq bibtex-dialect 'biblatex)
;; (add-hook 'find-file-hook 'TeX-fold-buffer t)
(setq-default TeX-master t) ;; https://emacs.stackexchange.com/a/71104/18414
(add-hook 'TeX-mode-hook 'flyspell-mode); Enable Flyspell mode for TeX modes such as AUCTeX. Highlights all misspelled words.
(setq LaTeX-babel-hyphen nil); Disable language-specific hyphen insertion
;; LaTeX-math-mode http://www.gnu.org/s/auctex/manual/auctex/Mathematics.html
;; (add-hook 'TeX-mode-hook 'LaTeX-math-mode)
;;; RefTeX: Turn on RefTeX for AUCTeX http://www.gnu.org/s/auctex/manual/reftex/reftex_5.html
(add-hook 'TeX-mode-hook 'turn-on-reftex)
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;; Persist history over Emacs restarts
(savehist-mode)
(setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
(global-diff-hl-mode)
(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
(require 'magit)
(setq magit-diff-highlight-indentation nil)
(setq magit-diff-highlight-trailing nil)
(setq magit-diff-paint-whitespace nil)
(setq magit-diff-highlight-hunk-body nil)
(remove-hook 'server-switch-hook 'magit-commit-diff)
(add-hook 'LaTeX-mode-hook 'writegood-mode)
(add-hook 'writegood-mode-hook 'writegood-passive-voice-turn-off)
(define-key outline-minor-mode-map (kbd "<M-tab>") 'outline-cycle)
(defun unpropertize-kill-ring ()
(setq kill-ring (mapcar 'substring-no-properties kill-ring)))
(add-hook 'kill-emacs-hook 'unpropertize-kill-ring)
(setq org-cycle-include-plain-lists 'integrate)
(add-hook 'org-mode-hook 'org-fragtog-mode)
(add-hook 'org-mode-hook (lambda ()
;; (local-set-key (kbd "C-c s") 'org-show-subtree)
(local-set-key (kbd "M-r") 'my-save-word)
(flyspell-mode -1)
(setq fill-column 100)))
;; (dolist (hook '(org-mode-hook))
;; (add-hook hook (lambda () (flyspell-mode 1))))
;; https://tex.stackexchange.com/a/64518/127048 -------------------------------
(put 'LaTeX-mode 'flyspell-mode-predicate 'auctex-mode-flyspell-verify)
(defun auctex-mode-flyspell-verify ()
"Function used for `flyspell-generic-check-word-predicate' in auctex mode."
(save-excursion
(forward-word -2)
(not (looking-at "renewcommand{"))))
(add-hook 'LaTeX-mode-hook
(lambda () (setq flyspell-generic-check-word-predicate
'auctex-mode-flyspell-verify)))
;; https://emacs.stackexchange.com/a/74193/18414 -------------------------------------
(defface font-latex-dollar-face
'((t :foreground "#f1fa8c"))
"Face for tikzpicture environment `$` sign."
:group 'font-latex-highlighting-faces)
(eval-after-load 'font-latex
(advice-add
'font-latex-match-dollar-math :around
(defun font-latex-match-dollar-math--around
(orig-fun &rest orig-args)
(pcase-let*
((`(,limit)
orig-args)
(val (apply orig-fun orig-args))
(beg (when val
(match-beginning 0)))
(end (when val
(match-end 0))))
(when (and beg
end
(save-excursion
(goto-char beg)
(looking-at-p (rx "$"))))
(set-match-data
(save-excursion
(list
(let* ((beg beg)
(end (progn (goto-char beg)
(skip-chars-forward (rx "$"))
(point))))
(prog1 end
(add-text-properties beg end '(
face font-latex-dollar-face
fontified t))))
(let* ((end end)
(beg (progn (goto-char end)
(skip-chars-backward (rx "$"))
(point))))
(prog1 beg
(add-text-properties beg end '(face font-latex-dollar-face
fontified t)))))))
val)))))
;; (advice-remove 'font-latex-match-dollar-math 'font-latex-match-dollar-math--around)
(define-key prog-mode-map (kbd "C-c C-u") #'insert-seperator)
(define-key prog-mode-map (kbd "C-c u") #'insert-seperator)
(defun latex-comment-todo ()
(interactive "*")
(insert "%% -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"))
(defun my_tex_view ()
(interactive)
(TeX-view))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-c C-u") 'latex-comment-todo)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-c u") 'latex-comment-todo)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "M-r") 'my-save-word))) ;; add new word to dictionary?
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "M-d") 'apheleia-format-buffer)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-c C-a") 'nil)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-c a") 'nil)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-x C-a") 'nil)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-x C-p") #'my_tex_view)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-x C-n") #'next-line)))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-c C-c") 'my-run-latex)))
(setq completion-styles '(orderless))
;; improve org mode looks
(setq org-hide-emphasis-markers t
org-startup-with-inline-images t
org-image-actual-width '(300))
(setq inhibit-compacting-font-caches t)
;; https://github.com/daviwil/emacs-from-scratch/blob/master/Emacs.org
(defun efs/org-font-setup ()
;; Replace list hyphen with dot
(font-lock-add-keywords 'org-mode
'(("^ *\\([-]\\) "
(0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
;; Set faces for heading levels
(dolist (face '((org-level-1 . 1.2)
(org-level-2 . 1.1)
(org-level-3 . 1.05)
(org-level-4 . 1.0)
(org-level-5 . 1.1)
(org-level-6 . 1.1)
(org-level-7 . 1.1)
(org-level-8 . 1.1)))
(set-face-attribute (car face) nil :font "Cantarell" :weight 'regular :height (cdr face)))
;; Ensure that anything that should be fixed-pitch in Org files appears that way
(set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
(set-face-attribute 'org-formula nil :inherit 'fixed-pitch)
(set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-table nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch)
(set-face-attribute 'line-number nil :inherit 'fixed-pitch)
(set-face-attribute 'line-number-current-line nil :inherit 'fixed-pitch))
;; Make sure org-indent face is available
(require 'org-indent)
(setq calendar-week-start-day 1)
(require 'dired-x)
(setq dired-omit-files
(concat "^\\.?#"
"\\|" "^\\.$"
"\\|" "\\.dvi$"
"\\|" "\\.log$"
"\\|" "\\.gz"
"\\|" "\\.out$"
))
(add-hook 'python-mode-hook (lambda () ;; https://github.com/naiquevin/sphinx-doc.el
(require 'sphinx-doc)
(sphinx-doc-mode t))) ;; C-c M-d
(setq org-blank-before-new-entry '((heading . t) (plain-list-item . auto)))
(global-set-key (kbd "M-d") 'nil)
(setq flycheck-check-syntax-automatically '(save mode-enable))
;; pine --------------------------------------------------------------------------
(defcustom pine-script-indent-pattern "\\(if \\|else[ \n]\\|for \\)"
"Regex pattern after which to add indentation.")
(defun pine-script-indent-line ()
"Set indentation based on indentation of previous line."
(interactive)
(let ((ccol (current-indentation))
pcol indp tcol)
(save-excursion
(beginning-of-line-text 0)
(setq pcol (current-column))
(setq indp (looking-at-p pine-script-indent-pattern))
(setq tcol (+ pcol (if indp tab-width 0))))
(if (equal ccol tcol)
(when (< (current-column) tcol)
(back-to-indentation))
(indent-line-to tcol))))
(defun pine-script-backtab ()
(interactive)
(indent-line-to
(max 0 (- (current-indentation) tab-width))))
(defun c/pinescript-indent ()
(setq indent-tabs-mode nil)
(setq tab-width 4)
(setq indent-line-function 'pine-script-indent-line)
(electric-indent-mode -1)
(local-set-key [backtab] 'pine-script-backtab))
(add-hook 'pine-script-mode-hook 'c/pinescript-indent)
(add-hook 'json-mode-hook
(lambda ()
(make-local-variable 'js-indent-level)
(setq tab-width 2) ;; works
(setq js-indent-level 2)))
(setq js-indent-level 2)
;; -------------------------------------------------------------
;; https://emacs.stackexchange.com/a/72909/18414
(defun fill-buffer-80-column ()
"Fill whole buffer"
(interactive)
(fill-region (point-min) (point-max)))
;; isearch -----------------------------------------------------------------------
(add-hook 'isearch-mode-hook (lambda () (display-line-numbers-mode 1)))
(add-hook 'isearch-mode-end-hook (lambda () (display-line-numbers-mode 0)))
(define-key isearch-mode-map (kbd "C-w") 'isearch-forward-symbol-at-point)
(defadvice isearch-repeat (after isearch-no-fail activate)
(unless isearch-success
(ad-disable-advice 'isearch-repeat 'after 'isearch-no-fail)
(ad-activate 'isearch-repeat)
(isearch-repeat (if isearch-forward 'forward))
(ad-enable-advice 'isearch-repeat 'after 'isearch-no-fail)
(ad-activate 'isearch-repeat)))
;; (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
(define-key isearch-mode-map (kbd "C-e") 'isearch-edit-string)
(define-key isearch-mode-map (kbd "TAB") 'isearch-del-char)
;; https://emacs.stackexchange.com/a/10583/18414 Make Isearch work across spaces, tabs, and newlines.
(setq isearch-lax-whitespace t
isearch-regexp-lax-whitespace t
search-whitespace-regexp "[ \t\r\n]+")
(define-advice isearch-repeat (:before (direction &optional count) goto-other-end)
"If reversing, start the search from the other end of the current match."
(unless (eq isearch-forward (eq direction 'forward))
(when isearch-other-end
(goto-char isearch-other-end))))
(gcmh-mode 1)
(setq save-place-file "~/.emacs.d/places")
(save-place-mode 1)
(setq-default save-place t)
(if (fboundp #'save-place-mode)
(save-place-mode +1)
(setq-default save-place t))
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
(setq org-startup-truncated nil)
(setf org-blank-before-new-entry '((heading . nil) (plain-list-item . nil)))
(defun my-old-carryover (old_carryover)
(save-excursion
(let ((matcher (cdr (org-make-tags-matcher org-journal-carryover-items))))
(dolist (entry (reverse old_carryover))
(save-restriction
(narrow-to-region (car entry) (cadr entry))
(goto-char (point-min))
(org-scan-tags '(lambda ()
(org-set-tags ":carried:"))
matcher org--matcher-tags-todo-only))))))
(setq org-journal-handle-old-carryover 'my-old-carryover)
(setq org-journal-skip-carryover-drawers (list "LOGBOOK"))
(setq org-journal-file-header 'org-journal-file-header-func)
(setq org-journal-file-type 'yearly)
(setq org-agenda-include-diary t)
;; https://emacs.stackexchange.com/a/47060/18414
(add-hook 'org-agenda-mode-hook #'org-super-agenda-mode)
(setq org-journal-date-format "%A, %d %B %Y")
(setq org-file-format "Diary %Y")
(defun org-journal-file-header-func (time)
"Custom function to create journal header."
(concat
(pcase org-journal-file-type
(`daily "#+TITLE: Daily Journal\n#+STARTUP: showeverything")
(`weekly "#+TITLE: Weekly Journal\n#+STARTUP: folded")
(`monthly "#+TITLE: Monthly Journal\n#+STARTUP: folded")
(`yearly "#+TITLE: Yearly Journal\n#+STARTUP: folded"))))
(defun xah-save-all-unsaved ()
(interactive)
(save-some-buffers t ))
(defun full-auto-save () ;; https://emacs.stackexchange.com/a/74517/18414
(interactive)
(save-excursion
(dolist (buf (buffer-list))
(set-buffer buf)
(unless (memq major-mode '(latex-mode))
(if (and (buffer-file-name) (buffer-modified-p))
(basic-save-buffer))))))
(add-hook 'auto-save-hook 'full-auto-save)
;; make source code look better
(defvar org-src-fontify-natively t)
(setq ivy-extra-directories nil)
(setq counsel-find-file-ignore-regexp "\\.elc\\'")
;; Fontify the whole line for headings (with a background color).
(setq org-fontify-whole-heading-line t)
;; (with-eval-after-load 'flycheck
;; (setq-default flycheck-disabled-checkers '(sh-posix-dash)))
;; https://emacs.stackexchange.com/a/44977/18414 ---------------------------------------
(global-set-key [remap goto-line] #'my-goto-line)
(defvar my-temp-linum-mode-sym
(if (fboundp 'display-line-numbers-mode)
'display-line-numbers-mode
'linum-mode)
"Use `display-line-numbers-mode' if it's available; `linum-mode' otherwise.")
(defun my-goto-line (line &optional buffer)
"`goto-line' with temporary line-numbering."
(interactive
(let ((my-temp-linum-buffer
;; Use the same prefix-arg behaviour as `goto-line'.
(if current-prefix-arg
(other-buffer (current-buffer) t)
(current-buffer))))
;; If line numbering is currently enabled in that buffer, then we
;; want to leave it alone.
(when (with-current-buffer my-temp-linum-buffer
(and (boundp my-temp-linum-mode-sym)
(symbol-value my-temp-linum-mode-sym)))
(setq my-temp-linum-buffer nil))
;; Prompt the user for the line number, using the interactive
;; form from `goto-line'. Line numbering will be enabled and
;; then disabled again during this procedure.
(eval (cadr (interactive-form 'goto-line)))))
;; Pass the line and buffer arguments to `goto-line'.
(goto-line line buffer))
(defun my-temp-linum-set-state (arg)
"Enable or disable line numbering."
(and (bound-and-true-p my-temp-linum-buffer)
(buffer-live-p my-temp-linum-buffer)
(with-current-buffer my-temp-linum-buffer
;; Call the specified mode function.
(funcall my-temp-linum-mode-sym arg))))
(defun my-temp-linum-enable-maybe ()
(my-temp-linum-set-state 1))
(defun my-temp-linum-disable-maybe ()
(my-temp-linum-set-state -1))
(add-hook 'minibuffer-setup-hook #'my-temp-linum-enable-maybe)
(add-hook 'minibuffer-exit-hook #'my-temp-linum-disable-maybe)
;; pylint-start -------------------------------------------------------------------
(setq python-python-command "~/venv/bin/python3"
python-shell-interpreter "~/venv/bin/python3"
python-shell-interpreter-args "-i"
python-shell-prompt-detect-failure-warning nil
flycheck-python-pycompile-executable "python3"
python-shell-completion-native-enable nil
python-shell-completion-native-disabled-interpreters '("python3")
lsp-pylsp-plugins-pylint-enabled t
lsp-pylsp-plugins-pylint-args ["--rcfile=~/.pylintrc"]
lsp-pyls-plugins-pylint-enabled nil)
(add-hook 'python-mode-hook
(lambda ()
(setq flycheck-python-pylint-executable "~/venv/bin/pylint")
(setq flycheck-pylintrc "~/.pylintrc")
(setq indent-tabs-mode nil
python-indent-offset 4
tab-width 4)
(let ((inhibit-message t))
(my-set-fill-column 80)
)))
(defun flycheck-python-setup ()
(flycheck-mode))
(add-hook 'after-init-hook #'global-flycheck-mode)
(setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc clojure-cider-typed))
(with-eval-after-load 'flycheck
(setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc)))
(setq-default flycheck-flake8-maximum-line-length 200)
(add-hook 'python-mode-hook 'lsp)
(defun flyspell-ignore-http-and-https ()
"Function used for `flyspell-generic-check-word-predicate' to ignore stuff starting with \"http\" or \"https\"."
(save-excursion
(forward-whitespace -1)
(when (looking-at " ")
(forward-char)
(not (looking-at "https?\\b")))))
(put 'text-mode 'flyspell-mode-predicate 'flyspell-ignore-http-and-https)
(put 'set-goal-column 'disabled nil)
(add-hook 'solidity-mode-hook 'flycheck-mode)
(add-hook 'solidity-mode-hook
(lambda ()
(set-fill-column 200)))
(with-eval-after-load 'flycheck (flycheck-pos-tip-mode))
(add-hook 'shell-script-mode
(lambda ()
(setq indent-tabs-mode nil)
(setq tab-width 4)
(untabify (point-min) (point-max))))
(define-error 'flycheck-ert-suspicious-checker "")
(defvar no-flyspell-list '("requirements.txt" ".help.md" "TODO" "\\.html$"))
(defun turn-off-flyspell-if-match ()
(if (member (file-name-nondirectory (buffer-file-name)) no-flyspell-list)
(flyspell-mode -1)))
(add-hook 'find-file-hook #'turn-off-flyspell-if-match)
;; (setq consult-git-grep-args "git --no-pager grep -F -n --no-color -I -e '%s' -- ':(exclude).gitignore'")
(add-hook 'after-init-hook #'global-flycheck-mode)
(with-eval-after-load 'flycheck
(setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc)))
;; (setq flycheck-python-flake8-executable "/usr/bin/python3") ;; skip venv
;; (setq flycheck-python-pylint-executable "/usr/bin/python3") ;; skip venv
(add-to-list 'flycheck-disabled-checkers 'python-flake8)
(setq flycheck-checker 'flake8)
(setq flycheck-flake8rc "~/.flake8rc")
(setq flycheck-python-complie-executable "/usr/bin/python3") ;; skip venv
(setq-default lsp-pyls-configuration-sources ["flake8"])
(add-hook 'python-mode-hook 'flycheck-mode)
(add-hook 'python-mode-hook 'python-docstring-mode)
(add-hook 'python-mode-hook #'lsp-deferred)
;;
(use-package python :ensure nil)
(add-hook 'python-mode-hook #'flycheck-python-setup)
(defun flycheck-next-error-loop-advice (orig-fun &optional n reset)
;; Optional: ensure flycheck cycles, both when going backward and forward.
;; Tries to handle arguments correctly.
;; Since flycheck-previous-error is written in terms of flycheck-next-error,
;; advising the latter is enough.
;; (message "flycheck-next-error called with args %S %S" n reset)
(condition-case err
(apply orig-fun (list n reset))
((user-error)
(let ((error-count (length flycheck-current-errors)))
(if (and
(> error-count 0) ; There are errors so we can cycle.
(equal (error-message-string err) "No more Flycheck errors"))
;; We need to cycle.
(let* ((req-n (if (numberp n) n 1)) ; Requested displacement.
; An universal argument is taken as reset, so shouldn't fail.
(curr-pos (if (> req-n 0) (- error-count 1) 0)) ; 0-indexed.
(next-pos (mod (+ curr-pos req-n) error-count))) ; next-pos must be 1-indexed
; (message "error-count %S; req-n %S; curr-pos %S; next-pos %S" error-count
; req-n curr-pos next-pos)
; orig-fun is flycheck-next-error (but without advise)
; Argument to flycheck-next-error must be 1-based.
(apply orig-fun (list (+ 1 next-pos) 'reset)))
(signal (car err) (cdr err)))))))
(advice-add 'flycheck-next-error :around #'flycheck-next-error-loop-advice)
(defun flycheck-or-norm-next-error (&optional n reset)
(interactive "P")
(if flycheck-mode
(flycheck-next-error n reset)
(next-error n reset)))
(defun flycheck-or-norm-previous-error (&optional n)
(interactive "P")
(if flycheck-mode
(flycheck-previous-error n)
(previous-error n)))
;; The following might be needed to ensure flycheck is loaded.
;; Hooking is required if flycheck is installed as an ELPA package (from any repo).
;; If you use ELPA, you might want to merge this with any existing hook you might have.
(add-hook 'after-init-hook
#'(lambda ()
(after-packages-loaded-hook)))
(global-set-key (kbd "M-g p") 'flycheck-or-norm-previous-error)
(global-set-key (kbd "C-z") nil)
(add-to-list 'flycheck-checkers 'solidity-checker)
(setq flycheck-solidity-solc-addstd-contracts t)
(setq solidity-flycheck-solc-checker-active t)
(setq flycheck-disabled-checkers '(python-pylint)) ;; running out side venv
(flycheck-add-next-checker 'python-flake8 'python-pylint 'python-mypy)
(define-key markdown-mode-map (kbd "M-d") 'fill-buffer-80-column)
(add-hook 'lsp-managed-mode-hook
(lambda ()
(when (derived-mode-p 'python-mode)
(add-to-list 'flycheck-disabled-checkers 'python-pylint)
(add-to-list 'flycheck-disabled-checkers 'python-pycompile)
(setq my/flycheck-local-cache
'((lsp . ((next-checkers . (python-flake8 python-mypy)))))))))
;; pylint-ended -------------------------------------------------------------------
(with-eval-after-load 'python ;; https://emacs.stackexchange.com/a/75575/18414
(setf (nth 7 python-font-lock-keywords-maximum-decoration)
`(,(rx symbol-start
(or
;; Python 2 and 3:
"ArithmeticError" "AssertionError" "AttributeError" "BaseException"
"BufferError" "BytesWarning" "DeprecationWarning" "EOFError"
"EnvironmentError" "Exception" "FloatingPointError" "FutureWarning"
"GeneratorExit" "IOError" "ImportError" "ImportWarning"
"IndentationError" "IndexError" "KeyError" "KeyboardInterrupt"
"LookupError" "MemoryError" "NameError" "NotImplementedError"
"OSError" "OverflowError" "PendingDeprecationWarning"
"ReferenceError" "RuntimeError" "RuntimeWarning" "StopIteration"
"SyntaxError" "SyntaxWarning" "SystemError" "SystemExit" "TabError"
"TypeError" "UnboundLocalError" "UnicodeDecodeError"
"UnicodeEncodeError" "UnicodeError" "UnicodeTranslateError"
"UnicodeWarning" "UserWarning" "ValueError" "Warning"
"ZeroDivisionError"
;; Python 2:
"StandardError"
;; Python 3:
"BlockingIOError" "BrokenPipeError" "ChildProcessError"
"ConnectionAbortedError" "ConnectionError" "ConnectionRefusedError"
"ConnectionResetError" "FileExistsError" "FileNotFoundError"
"InterruptedError" "IsADirectoryError" "NotADirectoryError"
"PermissionError" "ProcessLookupError" "RecursionError"
"ResourceWarning" "StopAsyncIteration" "TimeoutError"
;; OS specific
"VMSError" "WindowsError"
;; Custom
"QuietTerminate" "QuietExit" "Terminate" "Timeout" "Web3NotConnected" "IpfsNotConnected"
"HandlerException" "JobException" "BashCommandsException"
)
symbol-end)
. font-lock-type-face)))
;; ----------------------------------------------------------------------------
;; https://emacs.stackexchange.com/a/64165/18414
(setq projectile-cache-file (expand-file-name "projectile.cache"
user-emacs-directory)
projectile-known-projects-file (expand-file-name "projectile-known-projects.eld"
user-emacs-directory))
(setq projectile-known-projects-file "~/.emacs.d/tmp/projectile-bookmarks.eld")
(setq company-frontends
'(company-pseudo-tooltip-unless-just-one-frontend
company-preview-frontend
company-echo-metadata-frontend))
(defun my-scratch-buffer ()
"Create a new scratch buffer -- \*scratch\*"
(interactive)
(let ((n 0)
bufname buffer)
(catch 'done
(while t
(setq bufname (concat "*hello-world"
(if (= n 0) "" (int-to-string n))
"*"))
(setq n (1+ n))
(when (not (get-buffer bufname))
(setq buffer (get-buffer-create bufname))
(with-current-buffer buffer
(org-mode))
;; When called non-interactively, the `t` targets the other window (if it exists).
(throw 'done (display-buffer buffer t))) ))))
;; (setenv "MANWIDTH" "100") ;; (setenv "MANWIDTH" "120")
;; ?
(setq org-image-actual-width 400)
;; Drag-and-drop to `dired`
(add-hook 'dired-mode-hook 'org-download-enable)
(set-fringe-mode 0)
(setq Man-width-max 100)
(setq visible-cursor nil)
(set-frame-font "Menlo:size=9")
(setq default-frame-alist nil)
;; M-x org-display-inline-images
;; M-x org-redisplay-inline-images
;;;;;;;;;;;;;;;;;;;;;;
(setq org-descriptive-links -1)
(require 'lsp-pylsp) ;; https://emacs.stackexchange.com/a/68300/18414
(setq lsp-modeline-diagnostics-enable 1) ;; ??
(setq lsp-lens-enable nil)
(setq lsp-ui-sideline-enable nil)
(setq lsp-ui-sideline-show-diagnostics nil)
(setq lsp-file-watch-threshold 2000)
(setq lsp-signature-render-documentation nil)
(setq lsp-idle-delay 0.500)
(setq lsp-auto-guess-root nil)
(setq lsp-headerline-breadcrumb-enable nil) ;; https://emacs-lsp.github.io/lsp-mode/tutorials/how-to-turn-off/
(setq lsp-enable-symbol-highlighting nil)
(setq lsp-log-io nil) ; if set to true can cause a performance hit
;; (setq read-process-output-max (* 3 1024 1024))
(setq lsp-enable-snippet nil) ;; solves to prevent () to be added during completions
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;; (setq lsp-signature-auto-activate nil) ;; you could manually request them via `lsp-signature-activate`
(use-package lsp-mode
:ensure t
:commands (lsp lsp-deferred)
;; See https://emacs-lsp.github.io/lsp-mode/page/settings/mode/
;; for details on parameters
:config
(setq lsp-auto-guess-root t
lsp-log-io nil
lsp-restart 'auto-restart
lsp-enable-file-watchers nil
lsp-keep-workspace-alive nil
lsp-enable-symbol-highlighting nil
lsp-enable-on-type-formatting nil
lsp-signature-auto-activate nil
lsp-signature-render-documentation nil
lsp-eldoc-hook nil
lsp-eldoc-enable-hover nil
lsp-modeline-code-actions-enable nil
lsp-modeline-diagnostics-enable nil
lsp-headerline-breadcrumb-enable nil
lsp-semantic-tokens-enable nil
lsp-enable-folding nil
lsp-enable-imenu nil
lsp-enable-snippet nil
;;
lsp-lens-enable nil
lsp-ui-sideline-enable nil
lsp-ui-sideline-show-diagnostics nil
lsp-file-watch-threshold 2000
;;
read-process-output-max (* 3 1024 1024) ;; 1MB
lsp-idle-delay 0.5) ;; lsp-idle-delay 0.1)
(setq lsp-pylsp-plugins-yapf-enabled t
lsp-pylsp-plugins-flake8-enabled nil)
)
(with-eval-after-load "lsp-mode"
(setq lsp-restart 'ignore))
(menu-bar-mode -1)
(toggle-scroll-bar -1)
(tool-bar-mode -1)
(add-hook 'LaTeX-mode-hook
(defun my-LaTeX-mode-hook-100 ()
(flycheck-mode 1)
(flycheck-select-checker 'tex-lacheck)))
(setq flycheck-shellcheck-follow-sources nil)
(setq org-agenda-files '("~/Nextcloud/todo/todo-list.org"))
(defcustom org-pomodoro-play-sounds t
"Determines whether sounds are played or not."
:group 'org-pomodoro
:type 'boolean)
(setq org-capture-templates
'(("t" "todo" entry (file "~/Nextcloud/todo/todo-list.org")
"* TODO %i%? \n:LOGBOOK: \n:CREATED: %U \n:END:")))
(add-hook 'calendar-today-visible-hook 'calendar-mark-today)
;; Retain your default settings
(setq org-enforce-todo-dependencies t)
(setq org-enforce-todo-checkbox-dependencies t)
(setq org-agenda-dim-blocked-tasks t)
(require 'midnight) ;; https://www.emacswiki.org/emacs/MidnightMode
(midnight-mode)
(setq midnight-hook (list
(lambda ()
(require 'calendar)
(when (get-buffer calendar-buffer)
(with-current-buffer calendar-buffer
(calendar-redraw))))))
;; Create the custom agenda view
(setq org-agenda-custom-commands
'(("c"
"Agenda to show deadlines & hide blocked"
(
(agenda ""
((org-agenda-entry-types '(:deadline :scheduled))))
(tags-todo "-TODO=\"DONE\""
((org-agenda-skip-entry-if 'deadline 'scheduled)
(org-agenda-dim-blocked-tasks 'invisible)))
))))
(add-hook 'magit-mode-hook (lambda () (magit-delta-mode +1)))
(use-package magit-delta
:hook (magit-mode . magit-delta-mode))
(add-to-list 'auto-mode-alist '("\\.rst\\'" . rst-mode))
(defun alperis ()
(interactive)
(find-file "~/Nextcloud/todo/todo-list.org")
;; (add-hook 'after-init-hook 'org-agenda-list
(calendar)
(other-window 1))
(add-hook 'sh-mode-hook (lambda ()
(local-set-key (kbd "C-c C-c") 'nil)))
;; https://emacs.stackexchange.com/a/54944/18414
(defun my-org-export-each-headline-to-markdown (&optional max-level scope)
"Export each headline in the current buffer to a separate markdown file.
The title of each headline is used as the filename. Existing
files are overwritten.
With a prefix argument MAX-LEVEL, only headlines up to the specified level will
be exported.
If SCOPE is nil, the export will be performed on the entire buffer.
For other valid values of SCOPE, refer to `org-map-entries'."
(interactive "P")
(when max-level (setq max-level (format "LEVEL<=%s" max-level)))
;; Widen buffer temporarily as narrowing would affect the exporting.
(save-window-excursion
(org-with-wide-buffer
(save-mark-and-excursion
;; Loop through each headline.
(org-map-entries
(lambda ()
;; Get the plain headline text without statistics and make filename.
(let* ((title (car (last (org-get-outline-path t))))
(dir (file-name-directory buffer-file-name))
(filename (concat dir title ".md")))
;; Set the active region.
(set-mark (point))
(outline-next-preface)
(activate-mark)
;; Export the region to a markdown file.
(with-current-buffer (org-md-export-as-markdown)
;; Save the buffer to file and kill it.
(write-file filename)
(kill-current-buffer))))
"LEVEL=1" scope)))))
(setq csv-separators '("," ";" "\t"))
;; https://emacs.stackexchange.com/questions/361/how-can-i-hide-display-latex-section-just-like-org-mode-does-with-headlines
(add-hook 'LaTeX-mode-hook #'outline-minor-mode)
;; --------------------------------------------------------------
;; (require 'latex-extra)
;; (defun indent-fold ()
;; (interactive)
;; (indent-for-tab-command)
;; (latex/hide-show))
(add-hook 'LaTeX-mode-hook
(lambda ()
(local-set-key (kbd "C-c DEL") #'indent-fold)))
(add-hook 'LaTeX-mode-hook
(lambda ()
(local-set-key (kbd "C-c C-s") #'outline-show-entry)))
;; C-c @ C-a show-all
;; C-c @ C-c hide-entry
;; C-c @ C-d hide-subtree
;; C-c @ C-e show-entry
;; C-c @ TAB show-children
;; C-c @ C-k show-branches
;; C-c @ C-l hide-leaves
;; C-c @ C-o hide-other
;; C-c @ C-q hide-sublevels
;; C-c @ C-s show-subtree
;; C-c @ C-t hide-body
;; --------------------------------------------------------------
(defun my-truncate-lines-enable ()
(setq truncate-lines nil))
(add-hook 'csv-mode-hook 'my-truncate-lines-enable)
(setq shell-file-name "/bin/zsh")
;; -----------------------------------------------------------------
;; Allows multiple syntax checkers to run in parallel on Python code
;; Ideal use-case: pyflakes for syntax combined with mypy for typing
(use-package flycheck-pycheckers ;; flycheck-pycheckers ;; FIXME
:after flycheck
:ensure t
:init
(with-eval-after-load 'flycheck
(add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup)
)
(setq flycheck-pycheckers-checkers
'(
mypy3
;; pyflakes
)
)
)
(add-hook 'after-init-hook 'global-company-mode) ;; FIXME
(with-eval-after-load 'flycheck
(add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup))
(use-package typescript-mode
:after tree-sitter
:config
;; we choose this instead of tsx-mode so that eglot can automatically figure out language for server
;; see https://github.com/joaotavora/eglot/issues/624 and https://github.com/joaotavora/eglot#handling-quirky-servers
(define-derived-mode typescriptreact-mode typescript-mode
"TypeScript TSX")
;; use our derived mode for tsx files
(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescriptreact-mode))
;; by default, typescript-mode is mapped to the treesitter typescript parser
;; use our derived mode to map both .tsx AND .ts -> typescriptreact-mode -> treesitter tsx
(add-to-list 'tree-sitter-major-mode-language-alist '(typescriptreact-mode . tsx)))
(setq js-indent-level 2)
(add-hook 'js2-mode-hook 'prettier-js-mode)
(add-hook 'web-mode-hook 'prettier-js-mode)
(require 'hs-lint)
(defun my-haskell-mode-hook ()
(local-set-key "\C-cl" 'hs-lint))
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)
(setq flycheck-haskell-hlint-executable "/usr/local/bin/hlint")
(setq flycheck-ghc-args '("-Wno-missing-signatures" "-Wno-unused-top-binds"))
(global-display-fill-column-indicator-mode -1)
(global-diff-hl-mode -1)
;; -----------------------------------------------------------------
;; (setq debug-on-error nil)
(defun alper-end ()
(interactive)
(message "alper [ok]"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; superstart ---------------------------------------------- ;; ◉ do this
;; (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
;; (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1)))
;; (setq org-superstar-leading-bullet ?\s)
;; (setq org-indent-mode-turns-on-hiding-stars nil)
;; (setq org-superstar-special-todo-items t)
;; (use-package org-superstar
;; :after org
;; :hook (org-mode . org-superstar-mode)
;; :custom
;; (org-superstar-remove-leading-stars t)
;; (org-superstar-headline-bullets-list '("◉" "○" "✿" "⁖" "✸" "○"))
;; )
;; ------------------------------------------------------------------
;; (use-package org-alert
;; :ensure t)
;; (require 'alert)
;; (require 'org-alert)
;; (setq alert-default-style 'libnotify)
;; (setq org-alert-interval 300
;; org-alert-notify-cutoff 10
;; org-alert-notify-after-event-cutoff 10)
;; (run-with-idle-timer 300 t (lambda () (org-agenda nil "a")))
;; (require 'calfw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment