Skip to content

Instantly share code, notes, and snippets.

@zbroyar
Created December 3, 2021 11:37
Show Gist options
  • Save zbroyar/bbec769311154457de14360542e12924 to your computer and use it in GitHub Desktop.
Save zbroyar/bbec769311154457de14360542e12924 to your computer and use it in GitHub Desktop.
My .emacs
;;
;; Paths for Emacs itself
;;
;(setq merlin-debug 'message)
(setq
opam-prefix
(substring
(shell-command-to-string "/usr/local/bin/opam config var prefix 2>/dev/null") 0 -1))
(setq opam-bin (concat opam-prefix "/bin"))
(setq opam-share (concat opam-prefix "/share"))
(setq opam-emacs (concat opam-share "/emacs/site-lisp"))
(setq shell-file-name "/bin/sh")
(setenv
"PATH"
(concat
(concat opam-bin ":")
"/bin:"
"/sbin:"
"/usr/bin:"
"/usr/sbin:"
"/usr/local/bin:"
"/usr/local/sbin:"
"/Library/TeX/texbin:"
"/usr/local/opt/llvm/bin"
"~/bin:"
"~/.local/bin"
"~/.local/bin"
"~/.miniconda3/bin/"
"/usr/local/texlive/2017/bin/x86_64-darwin:"
"/Applications/Emacs.app/Contents/MacOS/bin"
(getenv "PATH")
)
)
(setenv "PGHOST" "127.0.0.1")
(setenv "PGPORT" "5432")
(setenv "PGUSER" "user")
(setenv "PGDATABASE" "db")
(setenv "PGPASSWORD" "dbpass")
(defun select-database (dbname)
"Set up appropriate environment parameters."
(interactive "sDatabase name: ")
(cond
((string-equal dbname "another_db") (setenv "PGDATABASE" "another_db"))
(t (setenv "PGDATABASE" "db"))
)
)
(setq exec-path (split-string (getenv "PATH") ":"))
(setq
load-path
(append
(list
"~/.emacs.d/opml"
"~/.emacs.d/misc"
"~/.emacs.d/emacs-nav"
"~/.emacs.d/color-theme"
"~/.emacs.d/matlab-emacs"
opam-emacs)
load-path))
;;
;; Requirements
;;
(require 'paren)
(require 'package)
(require 'cmake-mode)
(package-initialize)
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/"))
(elpy-enable)
(show-paren-mode 1)
(autoload 'hideshowvis-enable "hideshowvis" "Highlight foldable regions")
(autoload 'hideshowvis-minor-mode "hideshowvis" " " 'interactive)
(load-library "org-opml")
;(use-package flycheck :ensure t :init (global-flycheck-mode))
;;
;; LSP
;;
(setq lsp-keymap-prefix "C-c l")
(setq company-clang-executable "/usr/local/opt/llvm/bin/clangd")
(setq lsp-clients-clangd-executable "/usr/local/opt/llvm/bin/clangd")
(use-package lsp-mode
:ensure t
:commands lsp
:hook ((c-mode c++-mode csharp-mode) . lsp))
(use-package lsp-treemacs :ensure t)
;; (use-package lsp-ui
;; :ensure t
;; :hook (lsp-mode . lsp-ui-mode)
;; :config
;; (setq lsp-ui-sideline-enable t)
;; (setq lsp-ui-sideline-show-hover nil)
;; (setq lsp-ui-doc-position 'bottom)
;; ;; lsp config stuff
;; (setq lsp-enable-links nil)
;; (setq lsp-signature-render-documentation nil)
;; (setq lsp-headerline-breadcrumb-enable nil)
;; (setq lsp-ui-doc-enable nil)
;; (setq lsp-completion-enable-additional-text-edit nil)
;; (setq web-mode-enable-current-element-highlight t)
;; (lsp-ui-doc-show))
;; (setq lsp-ui-doc-show-with-cursor nil)
;;
;; Put autosave and backup files (ie #foo# and foo~) in one place, *not*
;; scattered all over the file system!
;;
(defvar autosave-dir "~/tmp/.autosaves/")
(make-directory autosave-dir t)
(defun auto-save-file-name-p (filename)
(string-match "^#.*#$" (file-name-nondirectory filename)))
(defun make-auto-save-file-name ()
(concat
autosave-dir
(if buffer-file-name
(concat "#" (file-name-nondirectory buffer-file-name) "#")
(expand-file-name
(concat "#%" (buffer-name) "#")))))
(defvar backup-dir (concat "~/tmp/emacs_backups/" (user-login-name) "/"))
(setq backup-directory-alist (list (cons "." backup-dir)))
;;
;; Everything is colored
;;
(require 'font-lock)
(require 'color-theme)
(color-theme-initialize)
(color-theme-deep-blue)
;;(color-theme-calm-forest)
;;
;; Frame status line look and feel
;;
(when (display-graphic-p) (tool-bar-mode -1))
(column-number-mode t)
(transient-mark-mode 0)
(setq-default scroll-step 1)
(setq-default desktop-enable t)
(setq-default icon-title-format (list "%b"))
(setq-default next-line-add-newlines nil)
(set-frame-position (selected-frame) 300 0)
(set-frame-size (selected-frame) 120 55)
;;
;; Faces fonts selectiones
;;
;;(set-fontset-font t 'cyrillic "FreeMono")
;;(set-fontset-font t 'unicode "FreeMono")
(set-face-attribute 'default nil :family "Monaco" :height 110 :weight 'normal)
;;(set-fontset-font t 'cyrillic "Courier New")
;;
;; Vi-like parenthesis movement
;;
(defun goto-match-paren (arg)
(interactive "p")
(message "%s" last-command)
(if
(not
(memq last-command '(left-char right-char set-mark
aquamacs-right-char aquamacs-left-char cua-set-mark
goto-match-paren down-list up-list end-of-defun
beginning-of-defun backward-sexp forward-sexp
backward-up-list forward-paragraph backward-paragraph
end-of-buffer beginning-of-buffer backward-word
forward-word mwheel-scroll backward-word forward-word
mouse-start-secondary mouse-yank-secondary
mouse-secondary-save-then-kill move-end-of-line
move-beginning-of-line backward-char forward-char next-line
previous-line scroll-up scroll-down scroll-left
scroll-right mouse-set-point next-buffer previous-buffer)
)
)
(self-insert-command (or arg 1))
(cond
((looking-at "\\s\(")
(forward-list 1)
(backward-char 1))
((looking-at "\\s\)")
(forward-char 1)
(backward-list 1))
(t (self-insert-command (or arg 1)))
)
)
)
;;
;; Useful functions
;;
(defun clear-space (arg)
"Kills all buffers except *scratch*"
(interactive "p")
(mapcar 'kill-buffer (buffer-list))
(cd "~/proj"))
;;
;; Global keys
;;
;;(define-key global-map "\C-cn" 'elfeed)
(define-key global-map "%" 'goto-match-paren)
(define-key global-map [\C-tab] 'other-window)
(define-key global-map "\r" 'newline-and-indent)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-cc" 'org-capture)
(define-key global-map "\C-ca" 'org-agenda)
(define-key global-map "\C-cb" 'org-iswitchb)
(define-key global-map [f7] 'fold-dwim-toggle)
(define-key global-map [\M-f7] 'fold-dwim-hide-all)
(define-key global-map [\M-f3] 'clear-space)
(define-key global-map [\S-\M-f7] 'fold-dwim-show-all)
;;(define-key global-map "\C-s" 'search-forward-regexp)
;;
;; Elfeed-org
;;
;;(require 'elfeed-org)
;;(elfeed-org)
;;(setq rmh-elfeed-org-files (list "~/.emacs.d/elfeed.org"))
;;
;; Lisp Mode
;;
(defun lisp-modes-hook ()
(turn-on-auto-fill)
(hideshowvis-enable)
(setq tab-always-indent t))
(add-hook 'lisp-mode-hook 'lisp-modes-hook)
(add-hook 'emacs-lisp-mode-hook 'lisp-modes-hook)
;;
;; Octave mode
;;
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
;;
;; HTML mode
;;
(add-to-list 'auto-mode-alist '("\\.html?" . html-mode))
(add-hook
'html-mode-hook
(lambda ()
(setq tab-width 2)
(setq indent-tabs-mode nil)
(setq tab-always-indent nil)))
;;
;; TradingView Pine Script Mode
;;
(require 'pine-script-mode)
(add-to-list 'auto-mode-alist '("\\.pine$" . pine-script-mode))
;;
;; PHP mode
;;
(autoload 'php-mode "php-mode" "Major mode for editing PHP code." t)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))
;;
;; OCaml mode
;;
(require 'merlin)
(require 'company)
(require 'ocp-indent)
(autoload 'tuareg-mode "tuareg" "Major mode for editing Caml code." t)
(autoload 'ocamldebug "ocamldebug" "Run the OCaml debugger" t)
(add-to-list 'auto-mode-alist '("\\.ml[iylp]?" . tuareg-mode))
(add-to-list 'auto-mode-alist '("\\.atd$" . tuareg-mode))
(dolist (ext '(".cmo" ".cmx" ".cma" ".cmxa" ".cmi"))
(add-to-list 'completion-ignored-extensions ext))
(defun eg-compile ()
(interactive)
(save-buffer)
(let*
((default-directory
(or
(locate-dominating-file buffer-file-name "Makefile") default-directory))
(compile-command
(concat
"(cd " default-directory
" && dune build @install && dune install)"))
(compilation-directory
(or (locate-dominating-file buffer-file-name "Makefile") nil)))
(recompile)))
(add-hook
'tuareg-mode-hook
(lambda ()
(setq tab-width 2)
(setq indent-tabs-mode nil)
(setq tab-always-indent nil)
(setq merlin-debug t)
(setq merlin-command 'opam)
(setq merlin-use-auto-complete-mode 'easy)
(setq tuareg-use-abbrev-mode t)
(setq tuareg-prettify-symbols-full t)
(setq merlin-completion-with-doc t)
(setq show-trailing-whitespace t)
(setq indent-line-function 'ocp-indent-line)
(setq indent-region-function 'ocp-indent-region)
(when (functionp 'prettify-symbols-mode)
(prettify-symbols-mode))
(merlin-mode)
(hideshowvis-enable)
(add-to-list 'company-backends 'merlin-company-backend)
(when (require 'merlin nil t)
(setq merlin-command 'opam)
(add-to-list 'auto-mode-alist '("/\\.merlin\\'" . conf-mode)))
(ocp-setup-indent)
(define-key tuareg-mode-map (kbd "M-c") 'eg-compile)
(define-key tuareg-mode-map (kbd "M-.") 'merlin-locate)
(define-key tuareg-mode-map (kbd "M-*") 'merlin-pop-stack)
(define-key tuareg-mode-map (kbd "M-p") 'merlin-error-prev)
(define-key tuareg-mode-map (kbd "M-n") 'merlin-error-next)
))
;;
;; Dune mode
;;
(require 'dune)
;; (require 'dune-flymake)
(add-to-list 'auto-mode-alist '("dune" . dune-mode))
;; (add-hook 'dune-mode-hook dune-flymake-dune-mode-hook)
;;
;; Matlab mode
;;
(autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
;;
;; Erlang mode
;;
;;(setq erlang-root-dir "/usr/local/lib/erlang/")
;;(require 'erlang-start)
;;(add-to-list 'auto-mode-alist '("\\.[eh]rl$" . erlang-mode))
;;(autoload 'erlang-mode "erlang" "Major mode for editing Erlang code." t)
;;(add-hook
;; 'erlang-mode-hook
;; (lambda ()
;; (setq tab-width 2)
;; (setq indent-tabs-mode t)
;; (setq tab-always-indent nil)))
;;
;; GnuPlot mode
;;
(require 'gnuplot)
(setq gnuplot-program "/usr/local/bin/gnuplot")
(add-to-list 'auto-mode-alist '("\\.\\(gp\\|gnuplot\\)$" . gnuplot-mode))
;;
;; C/C++ mode
;;
(add-to-list 'auto-mode-alist '("\\.c$" . c-mode))
(add-to-list 'auto-mode-alist '("\\.h" . c-mode))
(add-hook
`c-mode-common-hook
(lambda ()
(setq tab-width 2)
(setq indent-tabs-mode nil)
(setq tab-always-indent nil)
(setq c-basic-offset 2)
(setq c-default-style "bsd")
(hideshowvis-enable)
(xref-etags-mode 1)
(define-key c-mode-base-map (kbd "M-c") 'compile)
(define-key c-mode-base-map (kbd "C-c C-l") 'compile)
(define-key c-mode-base-map (kbd "M-*") 'pop-tag-mark)
(define-key c-mode-base-map (kbd "M-n") 'flycheck-next-error)
))
;;
;; C# mode
;;
(autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
(setq auto-mode-alist (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
(add-hook
`csharp-mode-hook
(lambda ()
(setq tab-width 4)
(setq indent-tabs-mode nil)
(setq tab-always-indent nil)
(setq c-basic-offset 4)
(setq c-default-style "bsd")
(xref-etags-mode 1)
(define-key c-mode-base-map (kbd "M-c") 'compile)
(define-key c-mode-base-map (kbd "C-c C-l") 'compile)
(define-key c-mode-base-map (kbd "M-*") 'pop-tag-mark)
(define-key c-mode-base-map (kbd "M-n") 'flycheck-next-error)
))
;;
;; XML mode
;;
(autoload 'xml-mode "xml-mode" "Major mode for editing XML." t)
(setq auto-mode-alist (append '(("\\.csproj$" . xml-mode)) auto-mode-alist))
;;
;; Org mode
;;
(require 'org-install)
(setq org-log-done 'time)
(setq org-directory "~/Org")
(setq org-clock-persist 'history)
(setq org-icalendar-include-todo t)
(setq org-icalendar-use-deadline
(quote
(event-if-not-todo
event-if-todo
todo-due)))
(org-clock-persistence-insinuate)
(setq org-footnote-auto-adjust t)
(org-babel-do-load-languages
'org-babel-load-languages
'(
(C . t)
(awk . t)
(dot . t)
(emacs-lisp . t)
(fortran . t)
(gnuplot . t)
(js . t)
(latex . t)
(lisp . t)
(makefile . t)
(ocaml . t)
(octave . t)
(org . t)
(python . t)
; (sh . t)
(sql . t)
))
(setq
org-agenda-files
(quote
(
"~/Org/Diary.org"
"~/Org/Notes.org"
)))
(setq org-mobile-use-encryption t)
(setq org-mobile-encryption-password "mobile-encryption-password")
(setq org-mobile-files org-agenda-files)
(setq org-mobile-directory "~/Org/Mobile")
(setq org-mobile-inbox-for-pull "~/Org/inbox.org")
;(setq org-todo-keywords
; '(
; (type "TODO" "|" "DONE")
; (sequence "PROJ" "|" "FINISHED")
; (sequence "PROG" "STARTED" "WAITING" "|" "CANCELLED" "DEFFERED" "DELEGATED" "DONE")
; )
; )
(setq org-default-notes-file (concat org-directory "/Notes.org"))
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(defun insert-equation (aligned)
"Insert equation at point"
(interactive)
(let (x s)
(if aligned
(setq x 29 s "\\begin{aligned}\n\n\\end{aligned}")
(setq x 15 s ""))
(insert (format "\\begin{equation}\n%s\n\\end{equation}" s))
(backward-char x)))
(add-hook
`org-mode-hook
(lambda ()
(define-key org-mode-map (kbd "C-c C-x C-q")
(lambda () (interactive) (insert-equation nil)))
(define-key org-mode-map (kbd "C-c C-x C-a")
(lambda () (interactive) (insert-equation 1))))
)
;;
;; Mozilla JavaScript mode
;;
(add-to-list 'auto-mode-alist '("\\.js$" . javascript-mode))
(add-hook
`js-mode-hook
(lambda ()
(setq c-basic-offset 2)
(setq tab-width 2)
(setq indent-tabs-mode nil)
))
;;
;; Solidity
;;
(require 'solidity-mode)
(add-to-list 'auto-mode-alist '("\\.sol" . solidity-mode))
(setq solidity-solc-path "/usr/local/bin/solc")
;;
;; Graphviz mode
;;
(require 'graphviz-dot-mode)
(add-to-list 'auto-mode-alist '("\\.gv$" . graphviz-dot-mode))
;;
;; Miscellaneous
;;
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(c-offsets-alist '((substatement-open . 0)))
'(custom-file "~/.emacs")
'(elpy-rpc-python-command "~/.miniconda3/bin/python3")
'(indicate-empty-lines t)
'(inhibit-startup-screen t)
'(initial-scratch-message nil)
'(ns-tool-bar-display-mode nil t)
'(ns-tool-bar-size-mode nil t)
'(package-selected-packages
'(omnisharp cmake-mode treemacs use-package lsp-ui lsp-mode csharp-mode php-mode pine-script-mode elpygen elpy company))
'(python-shell-interpreter "~/.miniconda3/bin/python3")
'(recentf-save-file nil)
'(select-enable-clipboard t)
'(show-trailing-whitespace t)
'(visual-line-mode nil t))
;; (org-todo-list nil)
;; (delete-other-windows)
(desktop-save-mode 1)
;; ## added by OPAM user-setup for emacs / base ## 56ab50dc8996d2bb95e7856a6eddb17b ## you can edit, but keep this line
(require 'opam-user-setup "~/.emacs.d/opam-user-setup.el")
;; ## end of OPAM user-setup addition for emacs / base ## keep this line
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment