Files
emacs-config/config.org
T
Arthur BARRAUX 5cfaf54de3 lsp
2024-10-21 14:40:56 +02:00

6.6 KiB

My Emacs Configuration

Init

Package management

  (require 'use-package)
  (setq use-package-always-ensure t)

  (setq package-archives
	'(("GNU ELPA"     . "https://elpa.gnu.org/packages/")
	  ("MELPA Stable" . "https://stable.melpa.org/packages/")
	  ("MELPA"        . "https://melpa.org/packages/"))
	package-archive-priorities
	'(("GNU ELPA"     . 10)
	  ("MELPA"        . 5)
	  ("MELPA Stable" . 0)))

Theme

(load-theme 'zenburn t)

Encoding

  (set-language-environment "UTF-8")
  (prefer-coding-system 'utf-8)

Completion

  (use-package vertico)
  (use-package consult)
  (use-package marginalia)

Company

  (use-package company)
  (company-mode 1)

Smart parenthesis

  (use-package smartparens
    :ensure smartparens  ;; install the package
    :hook (prog-mode text-mode markdown-mode) ;; add `smartparens-mode` to these hooks
    :config
    ;; load default config
    (require 'smartparens-config))

LSP

(setq package-selected-packages '(lsp-mode yasnippet lsp-treemacs helm-lsp
    projectile hydra flycheck company avy which-key helm-xref dap-mode))

(when (cl-find-if-not #'package-installed-p package-selected-packages)
  (package-refresh-contents)
  (mapc #'package-install package-selected-packages))

;; sample `helm' configuration use https://github.com/emacs-helm/helm/ for details
(helm-mode)
(require 'helm-xref)
(define-key global-map [remap find-file] #'helm-find-files)
(define-key global-map [remap execute-extended-command] #'helm-M-x)
(define-key global-map [remap switch-to-buffer] #'helm-mini)

(which-key-mode)
(add-hook 'c-mode-hook 'lsp)
(add-hook 'c++-mode-hook 'lsp)

(setq gc-cons-threshold (* 100 1024 1024)
      read-process-output-max (* 1024 1024)
      treemacs-space-between-root-nodes nil
      company-idle-delay 0.0
      company-minimum-prefix-length 1
      lsp-idle-delay 0.1)  ;; clangd is fast

(with-eval-after-load 'lsp-mode
  (add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration)
  (require 'dap-cpptools)
  (yas-global-mode))

Key-binds

C

Dereference arrow

  (defun print-arrow ()
	(interactive)
  (if (eq major-mode 'c-mode)
    (with-current-buffer (buffer-name);
      (insert "->"))
    (with-current-buffer (buffer-name);
	  (insert "ù"))
    ))
  (keymap-global-set "ù" 'print-arrow)

Jump to def

  (defun go-to-definition ()
    if (eq major-mode 'c-mode)
    ('ff-find-other-file))
  (keymap-local-set "C-<return>" 'go-to-definition)

Reload config

(defun reload-conf ()
  (interactive)
  (load-file "~/.emacs.default/init.el"))
(keymap-global-set "C-c r" 'reload-conf)

Open config

(defun open-config ()
  (interactive)
  (find-file "~/.emacs.default/config.org"))
(keymap-global-set "C-c c" 'open-config)

Window command

Split verticaly

(keymap-global-set "C-x é" 'split-window-below)

Split horizontally

(keymap-global-set "C-x \"" 'split-window-right)

Close window

(keymap-global-set "C-x à" 'delete-window)

Org

Org bullets

  (use-package org-bullets
    :config
    (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))

Font

    (font-lock-add-keywords 'org-mode
			    '(("^ *\\([-]\\) "
			       (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
  (custom-theme-set-faces
     'user
     '(variable-pitch ((t (:family "ETBembo" :height 220 :weight thin))))
     '(fixed-pitch ((t ( :family "Fira Code Retina" :height 200)))))
    (let* ((variable-tuple
	      (cond ((x-list-fonts "ETBembo")         '(:font "ETBembo"))
		    ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
		    ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
		    ((x-list-fonts "Verdana")         '(:font "Verdana"))
		    ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
		    (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro."))))
	     (base-font-color     (face-foreground 'default nil 'default))
	     (headline           `(:inherit default :weight bold :foreground ,base-font-color)))


      ;; Headlines
	(custom-theme-set-faces
	 'user
	 `(org-level-8 ((t (,@headline ,@variable-tuple))))
	 `(org-level-7 ((t (,@headline ,@variable-tuple))))
	 `(org-level-6 ((t (,@headline ,@variable-tuple))))
	 `(org-level-5 ((t (,@headline ,@variable-tuple))))
	 `(org-level-4 ((t (,@headline ,@variable-tuple :height 1.1))))
	 `(org-level-3 ((t (,@headline ,@variable-tuple :height 1.25))))
	 `(org-level-2 ((t (,@headline ,@variable-tuple :height 1.5))))
	 `(org-level-1 ((t (,@headline ,@variable-tuple :height 1.75))))
	 `(org-document-title ((t (,@headline ,@variable-tuple :height 2.0 :underline nil))))))

Emphasis markers

  (setq org-hide-emphasis-markers t)

Hooks

Variable pitch mode

(add-hook 'org-mode-hook 'variable-pitch-mode)

Visual line mode

(add-hook 'org-mode-hook 'visual-line-mode)

Custom faces

(custom-theme-set-faces
   'user
   '(org-block ((t (:inherit fixed-pitch))))
   '(org-code ((t (:inherit (shadow fixed-pitch)))))
   '(org-document-info ((t (:foreground "dark orange"))))
   '(org-document-info-keyword ((t (:inherit (shadow fixed-pitch)))))
   '(org-indent ((t (:inherit (org-hide fixed-pitch)))))
   '(org-link ((t (:foreground "royal blue" :underline t))))
   '(org-meta-line ((t (:inherit (font-lock-comment-face fixed-pitch)))))
   '(org-property-value ((t (:inherit fixed-pitch))) t)
   '(org-special-keyword ((t (:inherit (font-lock-comment-face fixed-pitch)))))
   '(org-table ((t (:inherit fixed-pitch :foreground "#83a598"))))
   '(org-tag ((t (:inherit (shadow fixed-pitch) :weight bold :height 0.8))))
   '(org-verbatim ((t (:inherit (shadow fixed-pitch))))))

Terminal

(use-package vterm)

Misceleaneous

Tool bar

(tool-bar-mode -1)

Menu bar

(menu-bar-mode -1)

Scroll bar

(scroll-bar-mode -1)

Global font

  (set-face-attribute 'default nil :family "Cascadia Mono" :height 200)