Configuration Minimal (sans librairies externes)
;; message de depart desactive
(setq inhibit-startup-message t)
;; menu-bar desactive
(menu-bar-mode -1)
;; Enlever le temps d'attente au demarage
(modify-frame-parameters nil '((wait-for-wm . nil)) )
;; Bip en mode visuel
(setq visible-bell t)
(defun my-visible-bell ()
(invert-face 'mode-line)
(run-with-timer 0.1 nil 'invert-face 'mode-line))
(setq visible-bell nil
ring-bell-function 'my-visible-bell)
;; enlever la barre d'outil
(tool-bar-mode -1)
(custom-set-variables '(toolbar-visible-p nil))
;; pas de scroll bars
(scroll-bar-mode -1)
;; encodage par defaut
(prefer-coding-system 'utf-8) ;;iso-8859-1-unix)
;; entrer dans le debugger si une erreur est trouvée
(setq debug-on-error t)
(setq debug-init t)
;; Quand le curseur est sur un tab, le curseur prend la taille de la tab
(setq-default x-stretch-cursor t)
;; taille de la tab
(setq-default tab-width 4)
;; Curseur non clignotant
(blink-cursor-mode 0)
;; Maximize (presque plein ecran)
(toggle-frame-maximized)
;; Pour ne pas avoir a taper en entier la reponse yes/no
(fset 'yes-or-no-p 'y-or-n-p)
;; ecrasement de la selection
(delete-selection-mode)
;; En francais les phrases ne se terminent pas par deux espaces (en americain si)
(setq sentence-end-double-space nil)
;; Mettre quatre espaces pour l'indentation
(setq c-basic-offset 4)
;; Quand on descend d'une ligne, la fenetre ne saute plus d'une demi-page
(setq scroll-margin 2)
(setq scroll-step 0)
(setq scroll-conservatively 10)
;; Laisser le curseur en place lors d'un défilement par pages.
(setq scroll-preserve-screen-position t)
;; sous-mots
;;(global-subword-mode 1)
;; Recherche automatique des fermetures et ouvertures des parentheses
(show-paren-mode 1)
;; Le chemin du fichier et son mode majeur dans la barre de titre
(setq-default frame-title-format `( " %b [%m]"))
;; Pour ne par taper sur 'inser' par erreur
(put 'overwrite-mode 'disabled t)
;; reutiliser la frame de gauche si presente
(add-to-list 'display-buffer-alist '("." nil (reusable-frames . t)))
;; activer narrow to region
(put 'narrow-to-region 'disabled nil)
;; souris invisible quand on tape
(setq make-pointer-invisible t)
;; on coupe les lignes
(setq-default global-visual-line-mode t)
;;; Temporarily reduce garbage collection during startup. Inspect `gcs-done'.
(defun ambrevar/reset-gc-cons-threshold ()
(setq gc-cons-threshold (car (get 'gc-cons-threshold 'standard-value))))
(setq gc-cons-threshold 8000000)
(add-hook 'after-init-hook #'ambrevar/reset-gc-cons-threshold)
;;; Temporarily disable the file name handler.
(setq default-file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
(defun ambrevar/reset-file-name-handler-alist ()
(setq file-name-handler-alist default-file-name-handler-alist))
(add-hook 'after-init-hook #'ambrevar/reset-file-name-handler-alist)
;;; Triggering GC whenever Emacs loses focus
(add-hook 'focus-out-hook 'garbage-collect)
;; Un gros fichier est superieur à 35mb
(setq large-file-warning-threshold (* 35 1024 1024))
;; historique
(setq-default history-length 1000)
(setq history-delete-duplicates t)
;; taille de la kill-ring
(setq kill-ring-max 1000)
;; Pour que la fenêtre de compilation ne soit pas trop grande
(setq compilation-window-height 10)
;; tronque les lignes lors d'un split window
;;(setq truncate-partial-width-windows 150)
;; raccourcis supplémentaires
(global-set-key (kbd "C-c e") 'eval-region) ;; lisp evaluation
(global-set-key (kbd "M-SPC") 'cycle-spacing) ;; cycle des espaces init => 1 => 0 => init
(global-set-key (kbd "<f1>") 'find-file-literally) ;; Ouvrir un fichier sans son mode majeur
(global-set-key (kbd "C-<return>") 'rectangle-mark-mode) ;; rectangle
(global-set-key (kbd "C-x *") 'calculator)
(global-set-key (kbd "C-* *") 'quick-calc)
;; pwd
(setq default-directory "~/")
;; indentation
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;; ne pas charger un ancien fichier compile
(setq load-prefer-newer t)
;; silence
(setq ad-redefinition-action 'accept)
;; compilation scroll
(setq compilation-scroll-output t)
;; font
(set-frame-font "DejaVuSansMono 9" nil t)
;; auto revert
(global-auto-revert-mode)
;; auto-fill
(auto-fill-mode -1)
;; display keystrokes
(setq echo-keystrokes 0.02)
;; Enable features that are disabled by default.
(put 'dired-find-alternate-file 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'scroll-left 'disabled nil)
;; lib path
(add-to-list 'load-path "~/.emacs.d/lisp")
(setq straight-check-for-modifications '(check-on-save))
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq package-enable-at-startup nil)
(use-package async
:straight t
:config
(async-bytecomp-package-mode 1))
(use-package ivy :straight t :defer 1)
(use-package google-c-style :straight t :defer 1)
(use-package epc :straight t :defer 1)
(use-package tablist :straight t :defer 1)
(use-package prettier-js :straight t :defer 1)
(use-package flycheck-pycheckers :straight t :defer 1)
(use-package bind-key :straight t)
(use-package smartrep :straight t)
(defun tangle-init-async ()
"If the current buffer is 'emacs-init.org' the code-blocks are tangled."
(when (equal (buffer-file-name) (expand-file-name (concat user-emacs-directory "init.org")))
(async-start
`(lambda ()
(require 'org)
(org-babel-tangle-file (expand-file-name (concat user-emacs-directory "init.org")) (expand-file-name (concat user-emacs-directory "init.el") "emacs-lisp")))
(lambda (result)
(byte-compile-file (expand-file-name (concat user-emacs-directory "init.el")))
;; scroll to the end to see if there's an error
(let ((buf (get-buffer "*Compile-Log*")))
(set-window-point (get-buffer-window buf) (buffer-size buf)))
(message "Tangled file compiled.")))))
(add-hook 'after-save-hook 'tangle-init-async)
(defun what-face (pos)
(interactive "d")
(let ((face (or (get-char-property pos 'read-face-name)
(get-char-property pos 'face))))
(if face (message "Face: %s" face) (message "No face at %d" pos))))
(add-to-list 'custom-theme-load-path "~/.emacs.d/lisp/")
(load-theme 'djangoliv t)
(use-package beacon
:straight t
:defer 1
:config
(beacon-mode 1)
(setq beacon-blink-when-focused t)
(setq beacon-size 3)
(setq beacon-color "lightblue")
)
(use-package dimmer
:straight t
:config
(setq dimmer-fraction 0.18)
(dimmer-mode)
)
(use-package exec-path-from-shell
:straight t
:config
(setq exec-path-from-shell-variables '("PATH"))
(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-env "PYTHONPATH")
(exec-path-from-shell-copy-env "WORKON_HOME"))
(global-set-key (kbd "s-s") 'copy-to-register)
(global-set-key (kbd "s-i") 'insert-register)
;; fichiers dans registre
(set-register ?e '(file . "~/.emacs"))
(set-register ?i '(file . "~/.emacs.d/init.org"))
(set-register ?o '(file . "~/.emacs-org/memo.org"))
(set-register ?t '(file . "~/.emacs-org/tel.org"))
(set-register ?p '(file . "~/.emacs-org/perso.org"))
(set-register ?b '(file . "~/.bashrc"))
(set-register ?k '(file . "~/.emacs-org/keys.org"))
(set-register ?c '(file . "~/.config/i3/config"))
(set-register ?x '(file . "/tmp/scratch.org"))
(set-register ?d '(file . "~/.emacs.d/lisp/djangoliv-theme.el"))
;; Pas d'auto-save
;;(setq auto-save-default nil)
;; Mettre tous les fichiers de backup dans un seul repertoire
(setq backup-directory-alist
'(("." . "~/.emacs-backup-files/")))
(setq version-control t ;; activation
vc-make-backup-files t ;; Faire aussi des backups des fichiers sous control de version
backup-by-copying t ;; on ne copie pas des liens
make-backup-files t ;; backup of a file the first time it is saved.
delete-old-versions t ;; delete excess backup files silently
kept-old-versions 2 ;; oldest versions to keep when a new numbered backup is made
kept-new-versions 6 ;; newest versions to keep when a new numbered backup is made
)
;; backup-walker
(use-package backup-walker :straight t)
;; savegarde de l'historique entre les sessions
(setq savehist-save-minibuffer-history 1)
(setq savehist-additional-variables
'(kill-ring search-ring regexp-search-ring log-edit-comment-ring shell-command-history last-kbd-macro)
savehist-file "~/.emacs.d/savehist")
(savehist-mode t)
;; pour que le colle de la souris soit dans la kill-ring
(setq select-enable-clipboard nil)
(setq select-enable-primary t)
(setq select-active-regions nil)
(setq mouse-drag-copy-region t)
(global-set-key [mouse-2] 'mouse-yank-at-click)
;; copie du clipboard
(use-package simpleclip
:straight t
:config
(defun paste-from-x-clipboard()
"Paste string clipboard"
(interactive)
(insert (simpleclip-get-contents)))
(global-set-key (kbd "S-<mouse-2>") 'paste-from-x-clipboard))
;; reverse pop kill ring
(defun yank-pop-forwards (arg)
(interactive "p")
(yank-pop (- arg)))
(global-set-key (kbd "M-Y") 'yank-pop-forwards) ; M-Y (Meta-Shift-Y)
;; browse-kill-ring
(use-package browse-kill-ring :straight t)
(global-set-key (kbd "C-x C-y") 'browse-kill-ring)
(setq browse-kill-ring-highlight-current-entry t)
(setq browse-kill-ring-highlight-inserted-item 'pulse)
;; yank rectangle end-of-line
(defun yank-rectangle-append-lines (&optional without-space)
"Yank each line of the current kill at the end of each subsequent line.
A space will be added between each line unless WITHOUT-SPACE which can
be passed in via a prefix arg."
(interactive "P")
(save-excursion
(let ((lines (split-string (current-kill 0) "\n")))
(dolist (line lines)
(goto-char (line-end-position))
(unless without-space
(just-one-space))
(insert line)
(unless (zerop (forward-line))
(insert "\n"))))))
;; efface la ligne si la region est inactive
(defadvice kill-region (before slick-cut activate compile)
"When called interactively with no active region, kill a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
;; yank in overwrite-mode
(defadvice yank (before yank-if-overwrite)
(if (bound-and-true-p overwrite-mode)
(delete-char (length (current-kill 0)))))
(ad-activate 'yank)
;; kill-word
(defun daedreth/kill-inner-word ()
"Kills the entire word your cursor is in. Equivalent to 'ciw' in vim."
(interactive)
(backward-word)
(kill-word 1))
(global-set-key (kbd "C-c k") 'daedreth/kill-inner-word)
;; kill line and append to kill-ring
(defun kill-line-and-append (&optional arg)
"Append kill-line to current kill buffer, prefix arg kills from beginning of line."
(interactive "P")
(append-next-kill)
(kill-line arg))
(global-set-key (kbd "C-S-k") 'kill-line-and-append)
;; kill buffers
(global-set-key (kbd "C-x k") 'kill-this-buffer)
;; Fermeture de tous les buffer sauf le courant
(defun kill-all-other-buffers ()
"Kill all other buffers."
(interactive)
(mapc 'kill-buffer (delq (current-buffer) (buffer-list))))
(defun kill-current-mode-buffers ()
"Kill all buffers that major mode same with current mode."
(interactive)
(kill-special-mode-buffers-internal major-mode))
(global-set-key (kbd "C-x C-k") 'kill-current-mode-buffers)
(defun kill-special-mode-buffers-internal (mode &optional except-current-buffer)
"Kill all buffers that major MODE same with special.
If option EXCEPT-CURRENT-BUFFER is `non-nil',
kill all buffers with MODE except current buffer."
(interactive)
(let ((current-buf (current-buffer))
(count 0))
(dolist (buffer (buffer-list))
(set-buffer buffer)
(when (and (equal major-mode mode)
(or (not except-current-buffer)
(not (eq current-buf buffer))))
(incf count)
(kill-buffer buffer)))
(message "Killed %s buffer%s" count (if (> count 1) "s" ""))))
;; control+wheel for zooming the text.
(global-set-key [(control mouse-4)] (lambda () (interactive) (text-scale-increase 1)))
(global-set-key [(control mouse-5)] (lambda () (interactive) (text-scale-decrease 1)))
;; mouse wheel for image-mode
(add-hook
'image-mode-hook
(lambda ()
(local-set-key [mouse-4] (lambda () (interactive) (image-previous-line 1)))
(local-set-key [mouse-5] (lambda () (interactive) (image-next-line 1)))
(local-set-key [(control mouse-4)] (lambda () (interactive) (image-increase-size 1)))
(local-set-key [(control mouse-5)] (lambda () (interactive) (image-decrease-size 1)))))
;; sensible a la casse
(setq-default case-fold-search t)
(define-key isearch-mode-map (kbd "C-c") 'isearch-toggle-case-fold)
;; tolerer les espaces
(setq isearch-lax-whitespace t)
(setq isearch-regexp-lax-whitespace t)
;; Ignore case by default:
(setq igrep-options "-i")
;; To search subdirectories by default:
(setq igrep-find t)
;; find grep
(setq find-grep-options "-q -i")
(setq grep-command "grep -nH -r --exclude-dir='svn' ")
(use-package restart-emacs
:straight t
:defer 1
:commands restart-emacs
)
Collection of Emacs Development Environment Tools
(global-ede-mode 1)
(add-to-list 'semantic-default-submodes 'global-semanticdb-minor-mode 1)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-scheduler-mode 1)
;;(add-to-list 'semantic-default-submodes 'global-semantic-stickyfunc-mode 1)
(add-to-list 'semantic-default-submodes 'global-semantic-highlight-func-mode 1)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode t)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode t)
(add-to-list 'semantic-default-submodes 'global-srecode-minor-mode t)
(add-to-list 'semantic-default-submodes 'global-semantic-decoration-mode t)
(setq semantic-load-turn-everything-on t)
(semantic-mode)
;;(use-package stickyfunc-enhance :straight t) ;; multilines concatene dans la header line
;; fichier en text-mode
(add-to-list 'auto-mode-alist '("\\.txt$" . text-mode))
(add-to-list 'auto-mode-alist '("\\`[^.]+\\'" . text-mode)) ;; fichiers sans extension
;; (_ / . - ~) ne separent pas les mots
(modify-syntax-entry ?_ "w" text-mode-syntax-table)
(modify-syntax-entry ?\/ "w" text-mode-syntax-table)
(modify-syntax-entry ?. "w" text-mode-syntax-table)
(modify-syntax-entry ?- "w" text-mode-syntax-table)
(modify-syntax-entry ?~ "w" text-mode-syntax-table)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(defun auto-fill-hook ()
(auto-fill-mode 1)
(setq fill-column 72))
(use-package i3wm-config-mode :straight t :defer 1)
(use-package dired
:straight (:type built-in)
:defer 0.5
:hook
(dired-mode . auto-revert-mode) ;; auto refresh dired when file changes
:custom
;; apparence
(dired-listing-switches "-lah --time-style long")
(directory-free-space-args "-Pkh")
;; wdired permet le changement des permissions
(wdired-allow-to-change-permissions t)
;; find-dired options
(find-ls-option '("-print0 | xargs -0 ls -ld" . "-ld"))
;; repertoire de copie par defaut
(dired-dwim-target t)
;; couleur par type de fichier
(dired-filetype-plain-regexp "^ .*\\.\\(TXT\\|txt\\|Txt\\|ini\\|INI\\|lrc\\|org\\|log\\|conf\\|CFG\\|cfg\\|properties\\|config\\|diff\\|patch\\|ebuild\\|inf\\|cnf\\|example\\|sample\\|default\\|m4\\|PARAM\\)$")
(dired-filetype-xml-regexp "^ .*\\.\\(html?\\|HTML?\\|xml\\|XML\\|xsl\\|xsd\\|rng\\|dtd\\|mht\\|jsp\\|asp\\|js\\|xaml\\|gml\\|GML\\|XSD\\|kml\\|KML\\)$")
;; récursivité
(dired-recursive-copies 'always)
(dired-recursive-deletes 'always)
:config
;; tris dans Dired
(defvar dired-sort-map (make-sparse-keymap))
(define-key dired-mode-map "s" dired-sort-map)
(defvar sort-params)
(defun dired-sort-by-size (arg)
"sort by Size"
(interactive "P")
(if (null arg)
(setq sort-params " -S")
(setq sort-params " -Sr"))
(dired-sort-other (concat dired-listing-switches sort-params)))
(defun dired-sort-by-extension (arg)
"sort by eXtension"
(interactive "P")
(if (null arg)
(setq sort-params " -X")
(setq sort-params " -Xr"))
(dired-sort-other (concat dired-listing-switches sort-params)))
(defun dired-sort-by-time (arg)
"sort by Time"
(interactive "P")
(if (null arg)
(setq sort-params " -t")
(setq sort-params " -tr"))
(dired-sort-other (concat dired-listing-switches sort-params)))
(defun dired-sort-by-Name (arg)
"sort by Name"
(interactive "P")
(if (null arg)
(setq sort-params " -N")
(setq sort-params " -Nr"))
(dired-sort-other (concat dired-listing-switches sort-params)))
(define-key dired-sort-map "s" 'dired-sort-by-size)
(define-key dired-sort-map "x" 'dired-sort-by-extension)
(define-key dired-sort-map "t" 'dired-sort-by-time)
(define-key dired-sort-map "n" 'dired-sort-by-Name)
(define-key dired-sort-map "?" (lambda () "sort help" (interactive) (message "s Size; x eXtension; t Time; n Name;")))
;; (de)compression
(define-key dired-mode-map "c" 'dired-do-compress-to)
(defvar dired-compress-files-alist
'(("\\.tar\\.gz\\'" . "tar -c %i | gzip -c9 > %o")
("\\.tgz\\'" . "tar -czf %i > %o")
("\\.zip\\'" . "zip %o -r --filesync %i"))))
(use-package dired-filetype-face :straight t)
(use-package dired-x
:straight (:type built-in)
:config
(define-key dired-mode-map (kbd "M-o") 'dired-omit-mode)
(setq-default dired-omit-files-p t)
(setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
(setq-default dired-omit-extensions '(".pyc" ".class" ".o" ".elc" "~")))
(use-package dired-k
:straight t
:config
(setq dired-k-style 'git)
(setq dired-k-human-readable t)
;; always execute dired-k when dired buffer is opened
(add-hook 'dired-initial-position-hook 'dired-k)
(add-hook 'dired-after-readin-hook #'dired-k-no-revert)
(define-key dired-mode-map (kbd "g") 'dired-k))
(define-key dired-mode-map (kbd "<return>") 'dired-find-alternate-file)
(define-key dired-mode-map (kbd "<right>") 'dired-find-file)
(define-key dired-mode-map (kbd "^") '(lambda () (interactive) (find-alternate-file "..")))
;; eww in dired
(define-key dired-mode-map "e" (lambda () (interactive) (eww-open-file (dired-get-file-for-visit))))
;; mouse
(defun dired-mouse-find-alternate-file (event)
"In dired, visit the file or directory you click on instead of the dired buffer."
(interactive "e")
(let (file)
(save-excursion
(set-buffer (window-buffer (posn-window (event-end event))))
(save-excursion
(goto-char (posn-point (event-end event)))
(setq file (dired-get-filename nil t))))
(select-window (posn-window (event-end event)))
(find-alternate-file (file-name-sans-versions file t))))
(define-key dired-mode-map [mouse-2] 'dired-mouse-find-alternate-file)
;; dired-isearch (permet de rechercher uniquement sur le nom des fichiers)
(use-package dired-isearch
:straight t
:defer 1
:config
(define-key dired-mode-map (kbd "C-s") 'dired-isearch-forward)
(define-key dired-mode-map (kbd "C-r") 'dired-isearch-backward)
(define-key dired-mode-map (kbd "ESC C-s") 'dired-isearch-forward-regexp)
(define-key dired-mode-map (kbd "ESC C-r") 'dired-isearch-backward-regexp))
(defun ediff-dired ()
(interactive)
(let* ((marked-files (dired-get-marked-files nil nil))
(other-win (get-window-with-predicate
(lambda (window)
(with-current-buffer (window-buffer window)
(and (not (eq window (selected-window)))
(eq major-mode 'dired-mode))))))
(other-marked-files (and other-win
(with-current-buffer (window-buffer other-win)
(dired-get-marked-files nil)))))
(cond ((= (length marked-files) 2)
(ediff-files (nth 0 marked-files)
(nth 1 marked-files)))
((and (= (length marked-files) 1)
(= (length other-marked-files) 1))
(ediff-files (nth 0 marked-files)
(nth 0 other-marked-files)))
(t (error "mark exactly 2 files, at least 1 locally")))))
;; diff dired (= sur fichiers region[mark point] dans dired ignore space)
(add-hook 'dired-load-hook
(lambda ()
(define-key dired-mode-map (kbd "s-=") 'ediff-dired)))
(setq diff-switches "-u --ignore-all-space")
;; mark backward
(defun dired-mark-backward ()
(interactive)
(call-interactively 'dired-mark)
(call-interactively 'dired-previous-line)
(call-interactively 'dired-previous-line))
;; unmark backward
(defun dired-unmark-backward ()
(interactive)
(call-interactively 'dired-unmark)
(call-interactively 'dired-previous-line)
(call-interactively 'dired-previous-line))
(define-key dired-mode-map (kbd "s-m") 'dired-mark-backward)
(define-key dired-mode-map (kbd "s-u") 'dired-unmark-backward)
(use-package dired-subtree
:straight t
:config
(setq dired-subtree-use-backgrounds nil)
(define-key dired-mode-map (kbd "i") 'dired-subtree-insert)
(define-key dired-mode-map (kbd "I") 'dired-subtree-remove))
(use-package peep-dired
:straight t
:defer 1
:config
(define-key dired-mode-map (kbd "P") 'peep-dired)
(setq peep-dired-cleanup-on-disable t)
(setq peep-dired-ignored-extensions '("mkv" "iso" "mp4" "zip" "tgz" "doc" "docx" "odt")))
(eval-after-load 'image-dired+ '(image-diredx-async-mode 1))
(setq image-dired-track-movement nil)
;; initialisation
(use-package org
:defer 1
:straight (:type built-in)
:bind
("C-M-<return>" . org-insert-heading-after-current)
("<S-C-up>" . nil)
("<S-C-down>" . nil)
("<S-C-right>" . nil)
("<S-C-left>" . nil)
:config
(setq org-startup-indented t)
(setq org-hide-emphasis-markers t)
(setq org-hide-leading-stars t)
(setq org-ellipsis " ••• ")
(setq org-startup-folded t)
(setq org-indent-mode t)
(setq org-use-speed-commands t)
(setq org-src-fontify-natively t) ;; fontify code in code blocks
(setq org-src-tab-acts-natively t) ;; indentation des block sources
(setq org-catch-invisible-edits 'show)
(setq org-startup-with-inline-images t)
(modify-coding-system-alist 'file "\\.org\\'" 'utf-8)
(setq org-cycle-separator-lines 0)
(add-hook 'ediff-prepare-buffer-hook #'outline-show-all) ;; edif in org-mode
(add-hook 'org-mode-hook (lambda ()
(turn-off-auto-fill)
(global-set-key (kbd "s-<escape>") 'hide-sublevels) ;; tout plier
(defadvice org-open-at-point (around org-open-at-point-choose-browser activate)
(let ((browse-url-browser-function 'browse-url-generic))
ad-do-it))
(setq indent-tabs-mode nil)
(setq-local line-spacing '0.1)
(setq-local company-minimum-prefix-length 5)))
;; keywords
(setq org-todo-keyword-faces
(quote
(("TODO" :foreground "red" :weight bold)
("IN-PROGRESS" :foreground "orange" :weight bold)
("WAIT" :foreground "cornsilk" :weight bold)
("VALID" :foreground "coral" :weight bold)
("CANCELED" :foreground "blue" :weight bold)
("NEEDSREVIEW" :foreground "firebrick" :weight bold))))
(setq org-todo-keywords
(quote
((sequence "TODO(t)" "IN-PROGRESS(i)" "WAIT(w)" "VALID(v)" "|" "DONE(d!)" "CANCELED(c@)" "NEEDSREVIEW(n@/!)"))))
;; org-find-tag
(push '(tags-tree . local) org-show-context-detail)
(define-key org-mode-map (kbd "C-x r J") 'org-tags-sparse-tree)
;; org-template s TAB, e TAB
(add-to-list 'org-structure-template-alist
'("m" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC" "<src lang=\"emacs-lisp\">\n?\n</src>"))
)
(use-package org-superstar
:straight t
:hook (org-mode . (lambda () (org-superstar-mode 1)))
:config
;;(setq org-superstar-headline-bullets-list '("◉" ("🞛" ?◈) "○" "▷"))
)
;; execution
(org-babel-do-load-languages
'org-babel-load-languages
'((shell . t)
(awk . t)
(latex . t)
(emacs-lisp . nil)
(ditaa . t)
(dot . t)
(plantuml . t)
(calc . t)
(gnuplot . t)
(R . t)
(python . t)))
;; dita
(setq org-ditaa-jar-path "~/Tools/ditaa/ditaa0_9.jar")
;; plantuml
(setq org-plantuml-jar-path "~/.emacs.d/plantuml/plantuml.jar")
;; don't prompt me to confirm everytime I want to evaluate a block
(setq org-confirm-babel-evaluate nil)
;; display/update images in the buffer after I evaluate
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)
;; for elisp
(define-key org-mode-map (kbd "C-.") 'find-function)
(setq org-export-coding-system 'utf-8)
;; export HTML avec css ("~/.emacs.d/org-style.css")
(defun my-org-inline-css-hook (exporter)
"Insert custom inline css"
(when (eq exporter 'html)
(let* ((dir (ignore-errors (file-name-directory (buffer-file-name))))
(path (concat dir "style.css"))
(homestyle (or (null dir) (null (file-exists-p path))))
(final (if homestyle "~/.emacs.d/org-style.css" path)))
(setq org-html-head-include-default-style nil)
(setq org-html-head (concat
"<style type=\"text/css\">\n"
"<!--/*--><![CDATA[/*><!--*/\n"
(with-temp-buffer
(insert-file-contents final)
(buffer-string))
"/*]]>*/-->\n"
"</style>\n")))))
;;(add-hook 'org-export-before-processing-hook 'my-org-inline-css-hook)
;; export pied de page
(setq org-html-validation-link nil)
(setq org-html-postamble t)
(setq org-html-postamble-format
'(("en" "<p class=\"author\">Author: %a (%e)</p>\n<p class=\"date\">Date: %T</p>")))
;; export table in csv
(defun export-table-to-csv (name)
"Search for table named `NAME` and export."
(interactive "s")
(show-all)
(let ((case-fold-search t))
(if (search-forward-regexp (concat "#\\+NAME: +" name) nil t)
(progn
(next-line)
(org-table-export (format "%s.csv" name) "orgtbl-to-csv")))))
(use-package org-re-reveal
:straight t
:config
(setq org-re-reveal-root "file:///home/ogiorgis/Tools/revealjs/reveal.js/")
(setq org-re-reveal-title-slide nil)
)
(defun org-begin-template ()
"Make a template at point."
(interactive)
(if (org-at-table-p)
(call-interactively 'org-table-rotate-recalc-marks)
(let* ((choices '(("s" . "SRC")
("e" . "EXAMPLE")
("q" . "QUOTE")
("v" . "VERSE")
("c" . "CENTER")
("l" . "LaTeX")
("h" . "HTML")
("a" . "ASCII")))
(key
(key-description
(vector
(read-key
(concat (propertize "Template type: " 'face 'minibuffer-prompt)
(mapconcat (lambda (choice)
(concat (propertize (car choice) 'face 'font-lock-type-face)
": "
(cdr choice)))
choices
", ")))))))
(let ((result (assoc key choices)))
(when result
(let ((choice (cdr result)))
(cond
((region-active-p)
(let ((start (region-beginning))
(end (region-end)))
(goto-char end)
(insert "#+END_" choice "\n")
(goto-char start)
(insert "#+BEGIN_" choice "\n")))
(t
(insert "#+BEGIN_" choice "\n")
(save-excursion (insert "#+END_" choice))))))))))
;;bind to key
(define-key org-mode-map (kbd "C-<") 'org-begin-template)
(add-hook 'org-mode-hook 'reveal-mode)
(use-package org-crypt
:straight (:type built-in)
:config
(org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance (quote ("crypt")))
(setq org-crypt-key nil)
(setq org-crypt-disable-auto-save t)
(define-key org-mode-map (kbd "M-?") 'org-decrypt-entry))
(setq calendar-location-name "Paris, France")
;; format jour/mois/an
(setq european-calendar-style t)
;; la semaine commence le lundi
(setq calendar-week-start-day 1)
;; jours et mois en francais
(setq calendar-column-width 3)
(setq calendar-day-name-array
["dimanche" "lundi" "mardi" "mercredi" "jeudi" "vendredi" "samedi"])
(setq calendar-day-header-array
["di" "lu" "ma" "me" "je" "ve" "sa"])
(setq calendar-month-name-array
["janvier" "fevrier" "mars" "avril" "mai" "juin"
"juillet" "aout" "septembre" "octobre" "novembre" "decembre"])
;; vacances
(eval-after-load 'calendar '(require 'french-holidays))
(setq calendar-holidays holiday-french-holidays)
(setq mark-holidays-in-calendar t)
(setq calendar-mark-holidays-flag t)
(setq calendar-view-holidays-initially t)
;; diary
(setq mark-diary-entries-in-calendar t
calendar-mark-diary-entries-flag t
view-diary-entries-initially t
number-of-diary-entries 7)
;; la date du jour
(add-hook 'calendar-today-visible-hook 'calendar-mark-today)
;; numero de la semaine dans calendar
(defun calendar-show-week (arg)
"Displaying week number in calendar-mode."
(interactive "P")
(copy-face font-lock-constant-face 'calendar-iso-week-face)
(set-face-attribute
'calendar-iso-week-face nil :height 0.7)
(setq calendar-intermonth-text
(and arg
'(propertize
(format
"%2d"
(car (calendar-iso-from-absolute
(calendar-absolute-from-gregorian
(list month day year)))))
'font-lock-face 'calendar-iso-week-face))))
(calendar-show-week t)
(when (locate-library "auctex.el")
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(setq TeX-PDF-mode t))
(use-package plantuml-mode
:straight t
:defer t
:config
(add-to-list 'auto-mode-alist '("\\.uml\\'" . plantuml-mode))
(setq plantuml-jar-path "~/.emacs.d/plantuml/plantuml.jar"))
(setq gnuplot-program "/usr/bin/gnuplot")
(setq auto-mode-alist (append '(("\\.\\(gp\\|gnuplot\\)$" . gnuplot-mode)) auto-mode-alist))
(use-package gnuplot-mode :straight t :defer 1)
(use-package graphviz-dot-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.dot\\'" . graphviz-dot-mode)))
(use-package crontab-mode :straight t :defer 1)
(use-package markdown-mode
:straight t
:defer t
:commands gfm-mode markdown-mode
:mode
("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.text\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode)
:custom
(markdown-command '("pandoc" "--from=markdown" "--to=html5")))
;; preview in eww
(autoload 'eww-mode "eww" "" t) ;; build-in
(defun markdown-preview-eww ()
(interactive)
(if (get-buffer "*html*")
(kill-buffer "*html*"))
(let* ((buf-this (buffer-name (current-buffer)))
(buf-html (get-buffer-create
(format "*preview (%s)*" buf-this))))
(markdown-other-window (buffer-name buf-html))
(eww-mode)
(shr-render-buffer buf-html)
(kill-buffer buf-html)))
;; live preview in firefox
(use-package flymd :straight t :defer 1)
;; Org-struct minor mode active in markdown mode.
(add-hook 'markdown-mode-hook 'turn-on-orgstruct)
(add-hook 'markdown-mode-hook
(lambda ()
(setq fill-column 102)))
(use-package sphinx-mode :straight t :defer 1)
(add-hook 'rst-mode-hook
(lambda ()
(setq fill-column 102)
(sphinx-mode)))
;; image manipulation
(use-package eimp
:straight t
:config
(add-hook 'image-mode-hook 'eimp-mode))
(use-package ereader
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.epub\\'" . ereader-mode)))
(use-package dotenv-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.env\\..*\\'" . dotenv-mode)))
(use-package all-the-icons :straight t )
(use-package centaur-tabs
:straight t
:defer 1
:after all-the-icons
:bind
("C-<prior>" . centaur-tabs-backward)
("C-<next>" . centaur-tabs-forward)
("C-S-<prior>" . centaur-tabs-move-current-tab-to-left)
("C-S-<next>" . centaur-tabs-move-current-tab-to-right)
("M-+" . centaur-tabs-backward-group)
("M--" . centaur-tabs-forward-group)
:init
(centaur-tabs-mode)
(setq centaur-tabs-cycle-scope 'tabs)
(setq centaur-tabs-set-modified-marker t)
(setq centaur-tabs-gray-out-icons 'buffer)
(setq centaur-tabs-set-icons t)
:config
(setq centaur-tabs-background-color (face-background 'default))
(setq centaur-tabs-style "box")
(setq centaur-tabs-set-bar 'over)
(setq centaur-tabs-icon-scale-factor 0.8)
;; exclude
(defun centaur-tabs-hide-tab (x)
(let ((name (format "%s" x)))
(or
(string-prefix-p "*" name)
(and (string-prefix-p "magit" name)
(not (file-name-extension name)))
)))
;; groups
(defun centaur-tabs-buffer-groups ()
(list
(cond
((derived-mode-p 'prog-mode) "Editing")
((derived-mode-p 'dired-mode) "Dired")
((derived-mode-p 'image-mode) "Image")
((derived-mode-p 'nxml-mode) "nXml")
((derived-mode-p 'logview-mode) "Logs")
((memq major-mode '(org-mode
org-agenda-clockreport-mode
org-src-mode
org-agenda-mode
org-beamer-mode
org-indent-mode
org-cdlatex-mode
org-agenda-log-mode
diary-mode))
"OrgMode")
((memq major-mode '(csv-mode
text-mode
latex-mode
rst-mode
markdown-mode
fundamental-mode))
"textMode")
(t
(centaur-tabs-get-group-name (current-buffer))))))
)
(use-package undo-tree
:straight t
:defer 0.5
:custom
(undo-tree-auto-save-history 1)
(undo-tree-visualizer-timestamps t)
(undo-tree-enable-undo-in-region nil)
:config
(global-undo-tree-mode 1)
(add-to-list 'undo-tree-incompatible-major-modes #'magit-status-mode)
(setq-default undo-tree-history-directory-alist (quote (("." . "~/.emacs-undo-files/"))))
(defun undo-toggle-diff ()
(interactive)
(if (equal undo-tree-visualizer-diff t)
(setq undo-tree-visualizer-diff nil)
(setq undo-tree-visualizer-diff t))
)
(global-set-key (kbd "C-c u") 'undo-toggle-diff)
(defun my-undo-tree-save-history (undo-tree-save-history &rest args)
(let ((message-log-max nil)
(inhibit-message t))
(apply undo-tree-save-history args)))
(advice-add 'undo-tree-save-history :around 'my-undo-tree-save-history)
)
;; Ffap ouvre sans confirm
;; remplace TRAVAIL par DEBUG ou KEEP si necessaire
;; lit le numero de ligne (si present) apres le signe : (suivi ou non d'un espace) ou apres line
(defun find-file-at-cursor-replace ()
(interactive)
(defvar line-number (and (string-match ":[0-9]+" (thing-at-point 'line))
(substring (thing-at-point 'line) (1+ (match-beginning 0)) (match-end 0))))
(if (null line-number)
(setq line-number (and (string-match "line [0-9]+" (thing-at-point 'line))
(substring (thing-at-point 'line) (+ 5 (match-beginning 0)) (match-end 0)))))
(if (null line-number)
(setq line-number (and (string-match ": [0-9]+" (thing-at-point 'line))
(substring (thing-at-point 'line) (+ 5 (match-beginning 0)) (match-end 0)))))
(if (null line-number)
(setq line-number "0"))
(let ( (path (if (region-active-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(thing-at-point 'filename) ) ))
(if (string-match-p "\\`https?://" path)
(browse-url path)
(progn ; not starting http://
(if (file-exists-p (replace-regexp-in-string "elc" "el" path ))
(find-file (replace-regexp-in-string "elc" "el" path ))
(if (file-exists-p (substitute-in-file-name path))
(find-file (substitute-in-file-name path))
(if (file-exists-p (concat path ".el"))
(find-file (concat path ".el"))
(if (file-exists-p (replace-regexp-in-string ":.*" "" path ))
(find-file (replace-regexp-in-string ":.*" "" path ))
(if (file-exists-p (replace-regexp-in-string "$i" "0" path ))
(find-file (replace-regexp-in-string "$i" "0" path ))
(if (file-exists-p (replace-regexp-in-string "a/" "" path ))
(find-file (replace-regexp-in-string "a/" "" path ))
(if (file-exists-p (replace-regexp-in-string "b/" "" path ))
(find-file (replace-regexp-in-string "b/" "" path ))
(if (file-exists-p (concat "/home/ogiorgis/workspaces/jupyterlab-projects/jupyterhub-projects/jupyterApps/app" path))
(find-file (concat "/home/ogiorgis/workspaces/jupyterlab-projects/jupyterhub-projects/jupyterApps/app" path))
(if (file-exists-p (concat "/home/ogiorgis/workspaces/" path))
(find-file (concat "/home/ogiorgis/workspaces/" path))
(if (file-exists-p (concat "/home/ogiorgis/workspaces/Mosaic/mosaic-board/" path))
(find-file (concat "/home/ogiorgis/workspaces/Mosaic/mosaic-board/" path))
(if (file-exists-p (concat "/home/ogiorgis/workspaces/TYMPAN/code_Tympan_Logilab/" path))
(find-file (concat "/home/ogiorgis/workspaces/TYMPAN/code_Tympan_Logilab/" path))
(when (y-or-n-p (format "file doesn't exist: '%s'. Create?" path))
(find-file path ))))))))))))))))
(forward-line (- (string-to-number line-number) 1)))
(global-set-key (kbd "C-<f1>") 'find-file-at-cursor-replace)
;; ffap avec la sourie (Ctrl click-droit)
(global-set-key [S-mouse-3] 'ffap-at-mouse)
(defun hungry-backspace (arg)
"Deletes preceding character or all whitespaces."
(interactive "*P")
(let ((here (point)))
(skip-chars-backward " \t")
(if (/= (point) here)
(delete-region (point) here)
(delete-char -1))))
(global-set-key (kbd "s-<backspace>") 'hungry-backspace)
(defun copy-line (&optional arg)
(interactive "P")
(read-only-mode 1)
(kill-line arg)
(read-only-mode 0))
(setq-default kill-read-only-ok t)
(global-set-key (kbd "C-c C-k") 'copy-line)
(defun delete-line ()
(interactive)
(delete-region
(point)
(save-excursion
(move-end-of-line 1) (point)))
(delete-char 1))
(defun backward-delete-line ()
(interactive)
(delete-region
(point)
(save-excursion (beginning-of-line 1) (point))))
(global-set-key (kbd "S-<backspace>") 'backward-delete-line)
(defun backward-kill-line ()
"Kill backward from point to beginning of line"
(interactive) (kill-line 0))
(global-set-key (kbd "M-<backspace>") 'backward-kill-line)
(defun copy-from-above-command (&optional arg)
(interactive "P")
(let ((cc (current-column)) n (string ""))
(save-excursion
(beginning-of-line)
(backward-char 1)
(skip-chars-backward "\ \t\n")
(move-to-column cc)
;; Default is enough to copy the whole rest of the line.
(setq n (if arg (prefix-numeric-value arg) (point-max)))
;; If current column winds up in middle of a tab,
;; copy appropriate number of "virtual" space chars.
(if (< cc (current-column))
(if (= (preceding-char) ?\t)
(progn
(setq string (make-string (min n (- (current-column) cc)) ?\s))
(setq n (- n (min n (- (current-column) cc)))))
;; In middle of ctl char => copy that whole char.
(backward-char 1)))
(setq string (concat string (buffer-substring
(point)
(min (line-end-position)
(+ n (point)))))))
(insert string)))
(global-set-key (kbd "s-y") 'copy-from-above-command)
(defun isearch-delete-something ()
(interactive)
(if (= 0 (length isearch-string))
(ding)
(setq isearch-string
(substring isearch-string
0
(or (isearch-fail-pos) (1- (length isearch-string)))))
(setq isearch-message
(mapconcat #'isearch-text-char-description isearch-string "")))
(if isearch-other-end (goto-char isearch-other-end))
(isearch-search)
(isearch-push-state)
(isearch-update))
(define-key isearch-mode-map (kbd "<backspace>") 'isearch-delete-something)
;; occur a partir de la recherche
(define-key isearch-mode-map (kbd "C-o") 'isearch-occur)
(defun isearch-occur ()
(interactive)
(let ((case-fold-search isearch-case-fold-search))
(occur (if isearch-regexp isearch-string (regexp-quote isearch-string)))))
(use-package avy-zap
:straight t
:config
(setq avy-zap-dwim-prefer-avy nil)
(global-set-key (kbd "M-z") 'avy-zap-up-to-char-dwim)
(global-set-key (kbd "M-Z") 'zop-to-char))
(use-package anzu
:straight t
:config
(global-anzu-mode +1))
(use-package drag-stuff
:straight t
:config
(drag-stuff-global-mode t)
(drag-stuff-define-keys)
;; org-mode gere mieux tout seul
(add-to-list 'drag-stuff-except-modes 'org-mode))
(use-package expand-region
:straight t
:defer 1
:bind
("C-@" . er/expand-region))
(use-package ediff
:straight nil
:bind
("s-=" . ediff-buffers)
:custom
;; ediff horizontal
(ediff-split-window-function 'split-window-horizontally)
;; evite la frame supplementaire
(ediff-window-setup-function 'ediff-setup-windows-plain)
:config
;; restore la configuration à la fin
(defvar ediff-last-windows nil "Last ediff window configuration.")
(defun ediff-restore-windows ()
"Restore window configuration to `ediff-last-windows'."
(set-window-configuration ediff-last-windows)
(remove-hook 'ediff-after-quit-hook-internal 'ediff-restore-windows))
(defadvice ediff-buffers (around ediff-restore-windows activate)
(setq ediff-last-windows (current-window-configuration))
(add-hook 'ediff-after-quit-hook-internal 'ediff-restore-windows) ad-do-it))
(setq-default ediff-forward-word-function 'forward-char)
(defun ediff-toggle-word-char ()
(interactive)
(if (equal 'forward-char ediff-forward-word-function)
(setq-default ediff-forward-word-function 'forward-word)
(setq-default ediff-forward-word-function 'forward-char))
(message "toggle ediff refinement to %s " ediff-forward-word-function))
(global-set-key (kbd "s-t") 'ediff-toggle-word-char)
(use-package ediff-trees
:straight t
:defer 1
:config
(global-set-key (kbd "s-SPC") 'ediff-trees-examine-next)
(global-set-key (kbd "S-s-SPC") 'ediff-trees-examine-previous)
(global-set-key (kbd "C-s-SPC") 'ediff-trees-examine-next-regexp)
(global-set-key (kbd "C-S-s-SPC") 'ediff-trees-examine-previous-regexp))
;; Revert-buffer
(defun revert-all-buffers ()
(interactive)
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (and (buffer-file-name) (not (buffer-modified-p)))
(revert-buffer t t t) )))
(message "Refreshed open files."))
(global-set-key (kbd "S-<f5>") 'revert-all-buffers)
(defun revert-buffer-no-confirm ()
(interactive)
(revert-buffer t t))
(global-set-key (kbd "<f5>") 'revert-buffer-no-confirm)
(use-package recentf
:straight nil
:hook (after-init . recentf-mode)
:bind
("M-r" . recentf-open-files)
:custom
(recentf-menu-path nil)
(recentf-menu-title "Recentf")
(recentf-menu-filter 'recentf-arrange-by-mode)
(recentf-filename-handler 'abbreviate-file-name)
(recentf-max-saved-items 150)
(recentf-auto-cleanup 'never)
:config
(run-at-time nil (* 25 60) 'recentf-save-list) ;; save list every 25 minutes
(add-to-list 'recentf-exclude "\\.emacs-persistent\\'")
(add-to-list 'recentf-exclude "\\.elc\\'")
(add-to-list 'recentf-exclude "\\@\\'")
(add-to-list 'recentf-exclude "\\TAGS\\'")
(add-to-list 'recentf-exclude ".pyc")
(add-to-list 'recentf-exclude "~$")
(add-to-list 'recentf-exclude "\\recentf\\'")
(add-to-list 'recentf-exclude ".emacs.d/straight"))
;; gérer les répertoires
(defun recentd-track-opened-file ()
"Insert the name of the directory just opened into the recent list."
(and (derived-mode-p 'dired-mode) default-directory
(recentf-add-file default-directory))
;; Must return nil because it is run from `write-file-functions'.
nil)
(defun recentd-track-closed-file ()
"Update the recent list when a dired buffer is killed.
That is, remove a non kept dired from the recent list."
(and (derived-mode-p 'dired-mode) default-directory
(recentf-remove-if-non-kept default-directory)))
(add-hook 'dired-after-readin-hook 'recentd-track-opened-file)
(add-hook 'kill-buffer-hook 'recentd-track-closed-file)
;; reouvrir le dernier fichier tué à la bonne ligne
(use-package saveplace
:straight (:type built-in)
:config
(defun always-save-place-to-alist ()
(let ((save-place t))
(save-place-to-alist)))
(add-hook 'kill-buffer-hook #'always-save-place-to-alist)
(defun restore-save-place ()
(save-place-find-file-hook)
(setq save-place nil)))
(defvar killed-buffer-list nil
"List of recently killed files.")
(defun add-file-to-killed-file-list ()
"If buffer is associated with a file name, add that file to the
`killed-file-list' when killing the buffer."
(when buffer-file-name
(push buffer-file-name killed-buffer-list)))
(add-hook 'kill-buffer-hook #'add-file-to-killed-file-list)
(defun reopen-killed-file ()
"Reopen the most recently killed file, if one exists."
(interactive)
(when killed-buffer-list
(find-file (pop killed-buffer-list))
(restore-save-place)
))
(global-set-key (kbd "C-x K") 'reopen-killed-file)
;; iterer entre les 2 buffers les plus récemment ouverts
(defun switch-to-recent-buffer ()
(interactive)
(switch-to-buffer nil))
(global-set-key (kbd "M-b") 'switch-to-recent-buffer)
;; ibuffer
(defalias 'list-buffers 'ibuffer) ;; ibuffer par defaut
;; ibbuffer groups
(setq ibuffer-saved-filter-groups
(quote (("default"
("Org"
(or
(name . "^\\*Calendar\\*$")
(name . "^diary$")
(mode . org-mode)))
("Main"
(or
(mode . c-mode)
(mode . shell-mode)
(mode . c++-mode)
(mode . perl-mode)
(mode . python-mode)))
("CSV"
(mode . csv-mode))
("ELisp"
(mode . emacs-lisp-mode))
("XML"
(mode . nxml-mode))
("Term"
(mode . term-mode))
("Dired"
(mode . dired-mode))
))))
(add-hook 'ibuffer-mode-hook
(lambda ()
(ibuffer-switch-to-saved-filter-groups "default")))
;; raccourcis dans le minibuffer
(defun shortway-in-minibuffer ()
;; Completion minibuffer
(interactive)
(backward-char 3)
(defvar found t)
(cond
((looking-at "hom") (setq directory "~/"))
((looking-at "doc") (setq directory "~/doc/"))
((looking-at "dev") (setq directory "~/dev/"))
((looking-at "for") (setq directory "~/workspaces/logilab/formation2"))
((looking-at "aff") (setq directory "~/workspaces/logilab/affaires"))
((looking-at "too") (setq directory "~/Tools"))
((looking-at "lis") (setq directory "~/.emacs.d/lisp/"))
(t (setq found nil)))
(cond (found (end-of-line)
(delete-region (point) (line-beginning-position))
(insert directory))
(t (forward-char 4)
(minibuffer-complete))))
(define-key minibuffer-local-completion-map (kbd "&") 'shortway-in-minibuffer)
;; historique completion
(define-key minibuffer-local-completion-map (kbd "<prior>") 'previous-complete-history-element)
(define-key minibuffer-local-completion-map (kbd "<next>") 'next-complete-history-element)
;; imprimier en pdf
(defun print-to-pdf ()
(interactive)
(setq ps-print-color-p nil)
(ps-spool-buffer-with-faces)
(switch-to-buffer "*PostScript*")
(write-file "/tmp/tmp.ps")
(kill-buffer "tmp.ps")
(defvar cmd (concat "ps2pdf14 /tmp/tmp.ps /tmp/" (buffer-name) ".pdf"))
(shell-command cmd)
(shell-command "rm /tmp/tmp.ps")
(message (concat "Saved to: /tmp/" (buffer-name) ".pdf")))
(defun define-trivial-mode(mode-prefix file-regexp &optional command)
(or command (setq command mode-prefix))
(let ((mode-command (intern (concat mode-prefix "-mode"))))
(fset mode-command
`(lambda ()
(interactive)
(read-only-mode t)
(start-process ,mode-prefix nil
,command (buffer-file-name))
(let ((obuf (other-buffer (current-buffer) t))
(kbuf (current-buffer)))
(set-buffer obuf)
(kill-buffer kbuf))))
(add-to-list 'auto-mode-alist (cons file-regexp mode-command))))
(define-trivial-mode "xls" "\\.xls$" "libreoffice")
(define-trivial-mode "xlsx" "\\.xlsx$" "libreoffice")
(define-trivial-mode "ods" "\\.ods$" "libreoffice")
(define-trivial-mode "odt" "\\.odt$" "libreoffice")
(define-trivial-mode "odt" "\\.odg$" "libreoffice")
(define-trivial-mode "doc" "\\.doc$" "libreoffice")
(define-trivial-mode "docx" "\\.docx$" "libreoffice")
(define-trivial-mode "ppt" "\\.ppt$" "libreoffice")
(define-trivial-mode "pptx" "\\.pptx$" "libreoffice")
(define-trivial-mode "odp" "\\.odp$" "libreoffice")
;; window manager
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)
;; windmove
;; (global-set-key (kbd "s-<left>") 'windmove-left)
;; (global-set-key (kbd "s-<right>") 'windmove-right)
;; (global-set-key (kbd "s-<down>") 'windmove-down)
;; (global-set-key (kbd "s-<up>") 'windmove-up)
(defun swap-windows ()
"If you have 2 windows, it swaps them."
(interactive)
(cond ((not (= (count-windows) 2))
(message "You need exactly 2 windows to do this."))
(t
(let* ((w1 (first (window-list)))
(w2 (second (window-list)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2)))
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1)))))
(defun rename-current-file-and-buffer ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
(defun delete-current-file-and-buffer ()
(interactive)
(let (currentFile)
(setq currentFile (buffer-file-name))
(when (yes-or-no-p (concat "Delete file?: " currentFile))
(kill-buffer (current-buffer))
(when (not (equal currentFile nil))
(delete-file currentFile) ) ) ) )
(defun write-file-copy (filename)
(interactive "F")
(write-region (point-min) (point-max) filename))
(global-set-key (kbd "C-x C-W") 'write-file-copy)
(defun my-create-non-existent-directory ()
(let ((parent-directory (file-name-directory buffer-file-name)))
(when (and (not (file-exists-p parent-directory))
(y-or-n-p (format "Directory `%s' does not exist! Create it?" parent-directory)))
(make-directory parent-directory t))))
(add-to-list 'find-file-not-found-functions 'my-create-non-existent-directory)
;; Afficher le nom du fichier dans le minibuffer et le mettre dans la kill-ring
(defun show-file-name ()
(interactive)
(message (buffer-file-name))
(kill-new (file-truename buffer-file-name)))
(global-set-key (kbd "C-x v f") 'show-file-name)
;; Afficher les informations du fichier courant
(defun show-file-info ()
(interactive)
(let* ((fname (buffer-file-name))
(data (file-attributes fname))
(access (current-time-string (nth 4 data)))
(mod (current-time-string (nth 5 data)))
(change (current-time-string (nth 6 data)))
(size (nth 7 data))
(mode (nth 8 data)))
(message
"%s:
Size: %s bytes
Accessed: %s
Modified: %s
Changed: %s
Mode: %s"
fname size access mod change mode)))
(global-set-key (kbd "C-x v i") 'show-file-info)
(use-package open-junk-file
:straight t
:defer 1
:config
(setq open-junk-file-format "/tmp/%Y%m%d-%H%M%S.")
(global-set-key (kbd "C-x r f") 'open-junk-file))
(setq-default ispell-program-name "aspell")
(setq ispell-local-dictionary "english")
(ispell-change-dictionary "english")
(setq ispell-personal-dictionary "~/.emacs.d/.ispell-dico-perso_en")
(setq ispell-silently-savep t)
(setq ispell-skip-sgml t)
(add-to-list 'ispell-skip-region-alist '("\\[\\[" . "\\]\\]"))
(defun toggleDictionary()
(interactive)
(let* ((dic ispell-current-dictionary)
(change (if (string= dic "francais") "english" "francais")))
(ispell-change-dictionary change)
(if (string= ispell-local-dictionary "english")
(setq ispell-personal-dictionary "~/.emacs.d/.ispell-dico-perso_en")
(setq ispell-personal-dictionary "~/.emacs.d/.ispell-dico-perso_fr"))
(message "Dictionary switched from %s to %s" dic change)
))
(global-set-key (kbd "s-$") 'toggleDictionary)
;; ;; ;; francais ou English
;; (defun toggleDictionary ()
;; (interactive)
;; (if (string= ispell-local-dictionary "english")
;; (progn
;; (ispell-change-dictionary "fr")
;; (setq ispell-local-dictionary "fr")
;; (setq ispell-personal-dictionary "~/.emacs.d/.ispell-dico-perso_fr"))
;; (progn
;; (ispell-change-dictionary "en")
;; (setq ispell-local-dictionary "en")
;; (setq ispell-personal-dictionary "~/.emacs.d/.ispell-dico-perso_en"))))
;; (global-set-key (kbd "s-$") 'toggleDictionary)
;; corrige et retient
(defun endless/ispell-word-then-abbrev (p)
"Corrige le mot précédent et le rajoute dans les abbreviations"
(interactive "P")
(let ((bef (downcase (or (car (ispell-get-word nil)) ""))) aft)
(call-interactively 'ispell-word)
(setq aft (downcase (or (thing-at-point 'word) "")))
(unless (or (string= aft bef) (string= bef ""))
(message "\"%s\" now expands to \"%s\" %sally"
bef aft (if p "loc" "glob"))
(define-abbrev
(if p local-abbrev-table global-abbrev-table)
bef aft))))
(setq save-abbrevs t)
(setq-default abbrev-mode t)
(setq abbrev-file-name "~/.emacs.d/personal_abbrv.txt")
(global-set-key (kbd "s-&") 'endless/ispell-word-then-abbrev)
;; exclusion pattern
(add-to-list 'ispell-skip-region-alist '("^http" . "\\]"))
(add-to-list 'ispell-skip-region-alist '("- \\*.+" . ".*\\*: "))
;; ispell et org-mode
(defun endless/org-ispell ()
"Configure `ispell-skip-region-alist' for `org-mode'."
(make-local-variable 'ispell-skip-region-alist)
(add-to-list 'ispell-skip-region-alist '(org-property-drawer-re))
(add-to-list 'ispell-skip-region-alist '("~" "~"))
(add-to-list 'ispell-skip-region-alist '("=" "="))
(add-to-list 'ispell-skip-region-alist '(":\\(PROPERTIES\\|LOGBOOK\\):" . ":END:"))
(add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC")))
(add-hook 'org-mode-hook #'endless/org-ispell)
(use-package verbiste :straight t :defer 1)
(use-package languagetool
:straight (:host github :repo "PillFall/Emacs-LanguageTool.el")
:config
(global-set-key (kbd "C-c l c") 'languagetool-check)
(global-set-key (kbd "C-c l d") 'languagetool-clear-buffer)
(global-set-key (kbd "C-c l p") 'languagetool-correct-at-point)
(global-set-key (kbd "C-c l b") 'languagetool-correct-buffer)
(global-set-key (kbd "C-c l l") 'languagetool-set-language)
(setq languagetool-language-tool-jar
"/home/ogiorgis/Tools/languageTool/LanguageTool-5.3/languagetool-commandline.jar")
(setq languagetool-java-arguments '("-Dfile.encoding=UTF-8"))
(setq languagetool-default-language "en-GB"))
;; firefox comme navigateur web par defaut
(setq browse-url-generic-program "/home/ogiorgis/Tools/firefox/firefox/firefox"
browse-url-browser-function 'browse-url-generic)
;; completion tuning
(setq dabbrev-abbrev-skip-leading-regexp "[<>=\"/\\:]'")
(global-set-key (kbd "s-/") 'dabbrev-expand)
(defconst dabbrev-always-check-other-buffers t) ;; ???
(defconst dabbrev-abbrev-char-regexp "\\sw\\|\\s_")
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-visible
try-complete-file-name-partially
try-complete-file-name
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-expand-whole-kill
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))
(global-set-key (kbd "M-/") 'hippie-expand)
;; Exclude very large buffers from dabbrev
(defun exclude-big-friend-buffer (other-buffer)
(< (buffer-size other-buffer) (* 1 1024 1024)))
(setq dabbrev-friend-buffer-function 'exclude-big-friend-buffer)
;; Ignorer la casse pour la completion des chemins de fichiers
(setq read-file-name-completion-ignore-case t)
;; completion case sensitive
(setq completion-ignore-case nil)
(use-package puppet-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.pp$" . puppet-mode)))
(use-package wrap-region
:straight t
:config
(add-to-list 'wrap-region-except-modes 'calendar-mode)
(wrap-region-global-mode t)
(wrap-region-add-wrapper "*" "*" nil 'org-mode)
(wrap-region-add-wrapper "/" "/" nil 'org-mode)
(wrap-region-add-wrapper "=" "=" nil 'org-mode)
(wrap-region-add-wrapper "~" "~" nil 'org-mode)
(wrap-region-add-wrapper "_" "_" nil 'org-mode)
(wrap-region-add-wrapper "+" "+" nil 'org-mode))
(setq my-tramp-ssh-completions
'((tramp-parse-sconfig "~/.ssh/config")
(tramp-parse-shosts "~/.ssh/known_hosts")))
(setq tramp-auto-save-directory "~/.emacs-autosave-tramp-files/")
(setq tramp-backup-directory-alist backup-directory-alist)
(setq tramp-persistency-file-name "/tmp/.tramp")
;; se souviens du mot de passe ~/.authinfo.gpg
(setq password-cache-expiry nil)
;; ouvrir un fichier en sudo
(defun sudo-find-file (file)
"Opens FILE with root privileges."
(interactive "FFind file: /sudo::")
(set-buffer
(find-file (concat "/sudo::" (expand-file-name file)))))
;;(global-set-key (kbd "s-r") 'sudo-find-file)
(set-default 'tramp-default-proxies-alist (quote (("giorgis" "sag" "djangoliv" "/ssh:%h:"))))
;; ouvrir un fichier distant en sudo
(defun sudo-remote-find-file (file)
"Opens repote FILE with root privileges."
(interactive "FFind file: ")
(setq begin (replace-regexp-in-string "scp" "ssh" (car (split-string file ":/"))))
(setq end (car (cdr (split-string file "@"))))
(set-buffer
(find-file (format "%s" (concat begin "|sudo:root@" end)))))
;; refresh as sudo
(defun sudo-revert ()
(interactive)
(setq theLine (line-number-at-pos))
(let ((f (buffer-file-name)))
(when f
(let ((content (when (buffer-modified-p)
(widen)
(buffer-string))))
(revert-buffer)
(kill-buffer (current-buffer))
(find-file (concat "/sudo::" f))
(when content
(let ((buffer-read-only nil))
(erase-buffer)
(insert content))))))
(forward-line (- theLine 1)))
(use-package palette :straight t :defer 1)
;; compilation lisp
(defun byte-compile-current-file ()
"interactive command for byte compiling current file."
(interactive)
(byte-compile-file (buffer-file-name)))
(global-set-key (kbd "s-b") 'byte-compile-current-file)
;;Conversion des fins de lignes du format MS-DOS au format Unix
(defun dos2unix ()
(interactive)
(goto-char (point-min))
(while (search-forward "\r" nil t)
(replace-match ""))
(while (re-search-forward "\015" nil t)
(replace-match "" nil nil))
(set-buffer-file-coding-system 'unix 't))
;; Conversion des fins de lignes du format Unix au format MS-DOS (retour chariot)
;; (defun unix2dos ()
;; (interactive)
;; (save-excursion
;; (goto-char (point-min))
;; (while (search-forward "\n" nil t) (replace-match "\r\n"))))
;; home va au debut de la ligne puis à l'indentation
(defun smarter-move-beginning-of-line (arg)
"Début de ligne puis début d'indentation (cycle)"
(interactive "^p")
(setq arg (or arg 1))
(when (/= arg 1)
(let ((line-move-visual nil))
(forward-line (1- arg))))
(let ((orig-point (point)))
(move-beginning-of-line 1)
(when (= orig-point (point))
(back-to-indentation)
)))
;; remap C-a (et home)
(global-set-key [remap move-beginning-of-line] 'smarter-move-beginning-of-line)
;; comment box
(defun comment-box-line (b e)
(interactive "r")
(let ((e (copy-marker e t)))
(goto-char b)
(end-of-line)
(insert-char ? (- fill-column (current-column)))
(comment-box b e 1)
(goto-char e)
(set-marker e nil)))
(global-set-key (kbd "C-M-;") 'comment-box) ;;-line)
;; insertion de la date
(defun insert-date ()
"Insert date at point."
(interactive)
(insert (format-time-string "%a %Y-%m-%d - %l:%M %p")))
;; centre l'ecran horizontalement en centrant le curseur
(defun horizontal-recenter ()
"make the point horizontally centered in the window"
(interactive)
(let ((mid (/ (window-width) 2))
(line-len (save-excursion (end-of-line) (current-column)))
(cur (current-column)))
(if (< mid cur)
(set-window-hscroll (selected-window) (- cur mid)))))
(global-set-key (kbd "C-S-l") 'horizontal-recenter)
;; effacer les lignes dupliquees
(defun uniquify-all-lines-region (start end)
"Find duplicate lines in region START to END keeping first occurrence."
(interactive "*r")
(save-excursion
(let ((end (copy-marker end)))
(while
(progn
(goto-char start)
(re-search-forward "^\\(.*\\)\n\\(\\(.*\n\\)*\\)\\1\n" end t))
(replace-match "\\1\n\\2")))))
(defun remove-duplicate-lines ()
"Delete duplicate lines in buffer and keep first occurrence."
(interactive "*")
(uniquify-all-lines-region (point-min) (point-max)))
;; increment region
(defun increment-progressively-numbers-in-region (start end arg)
(interactive "r\np")
(increment-numbers-in-region start end arg arg))
(defun increment-numbers-in-region (start end arg &optional progressive-increment)
(interactive "r\np")
(goto-char start)
(let ((increment (or arg 1))
(progressive-increment (or progressive-increment 0))
(previous-line-number (line-number-at-pos)))
(while
(re-search-forward "[0-9]+" end t)
(when (> (line-number-at-pos) previous-line-number)
(setq increment (+ increment progressive-increment))
(setq previous-line-number (line-number-at-pos)))
(let ((incremented-string (int-to-string (+ increment (string-to-number (match-string 0))))))
;; If incremented string and original match differ in length, update end point
(setq end (+ end (- (length incremented-string) (length (match-string 0)))))
(replace-match incremented-string)))))
(defun intelligent-close ()
(interactive)
(if (eq (car (visible-frame-list)) (selected-frame))
;;for parent/master frame...
(if (> (length (visible-frame-list)) 1)
;;close a parent with children present
(if (y-or-n-p "Really kill That Frame ? ")
(delete-frame (selected-frame)))
;;close a parent with no children present
(save-buffers-kill-emacs))
;;close a child frame
(delete-frame (selected-frame))))
(global-set-key (kbd "C-x C-c") 'intelligent-close)
(defun kill-emacs-force ()
"Use `call-process' to send ourselves a KILL signal."
(interactive)
(call-process "kill" nil nil nil "-9" (number-to-string (emacs-pid))))
(global-set-key (kbd "C-x C") 'kill-emacs-force)
(defun indent-buffer ()
(interactive)
(indent-region (point-min) (point-max)))
(defun indent-region-or-buffer ()
"Indents a region if selected, otherwise the whole buffer"
(interactive)
(save-excursion
(if (region-active-p)
(progn
(indent-region (region-beginning) (region-end))
(message "Indented selected region"))
(progn
(indent-buffer)
(message "Indented buffer")))))
(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)
(defun remove-blank-lines ()
"remove blank lines"
(interactive)
(goto-char (point-min))
(while (re-search-forward "\\(^\\s-*$\\)\n" nil t)
(replace-match "")
(forward-char 1)))
(defun remove-extra-blank-lines ()
"replace multiple blank lines with a single one"
(interactive)
(goto-char (point-min))
(while (re-search-forward "\\(^\\s-*$\\)\n" nil t)
(replace-match "\n")
(forward-char 1)))
(defun grepPDF(directory pattern)
(interactive "Ddirectory: \ns pattern: ")
(call-process-shell-command
(format "find %s -name '*.pdf' -exec sh -c 'pdftotext \"{}\" - | grep -i --with-filename --label=\"{}\" --color \"%s\"' \\;" directory pattern) nil "*grepPDF*" t)
(pop-to-buffer "*grepPDF*")
(compilation-mode))
(use-package vlf :straight t)
(defun untabify-buffer ()
"Untabify the entire buffer."
(interactive)
(untabify (point-min) (point-max)))
(defun tabify-buffer ()
"tabify the entire buffer."
(interactive)
(tabify (point-min) (point-max)))
(defun select-and-right ()
(interactive)
(if (not mark-active)
(set-mark-command nil))
(forward-word))
(global-set-key (kbd "C-[ <down>") 'select-and-right) ;; ESC-down
(defun select-and-left ()
(interactive)
(if (not mark-active)
(set-mark-command nil))
(backward-word))
(global-set-key (kbd "C-[ <up>") 'select-and-left) ;; ESC-up
;; (defun duckduckgo ()
;; "duckduckgo a query or region if any."
;; (interactive)
;; (browse-url
;; (concat
;; "https://duckduckgo.com/?q="
;; (if mark-active
;; (buffer-substring (region-beginning) (region-end))
;; (read-string "Search: ")))))
;; ;; M-s M-w recherche la région, si pas de sélection => prompt
;; (defun jab/eww-search (orig-fun &rest args)
;; (if (region-active-p) (apply orig-fun args)
;; (eww (read-string "Query: "))))
;; (advice-add 'eww-search-words :around #'jab/eww-search)
(use-package logview
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\log.txt\\'" . logview-mode))
(add-to-list 'auto-mode-alist '("\\.log\\'" . logview-mode))
(custom-set-variables '(logview-additional-submodes
(quote
(("kube Format"
(format . "[LEVEL TIMESTAMP NAME")
(levels . "kubeLevels")
(aliases)) )))
'(logview-additional-level-mappings
(quote (("kubeLevels" . ((error "E")(warning "W")(information "I")(debug "D")(trace "T"))))))
'( logview-additional-timestamp-formats
'(("MMM-dd HH:mm:ss.SSS"
(java-pattern . "MMM-dd HH:mm:ss.SSS"))))
)
)
(use-package syslog-mode :straight t :defer 1)
(use-package unaccent :straight t :defer 1)
(defun toggle-letter-case ()
(interactive)
(let ((case-fold-search nil))
(cond
((looking-at "[[:lower:]]") (upcase-region (point) (1+ (point))))
((looking-at "[[:upper:]]") (downcase-region (point) (1+ (point)))))
(right-char)))
(global-set-key (kbd "M-C") 'toggle-letter-case)
(defun sk/dcaps-to-scaps ()
"Convert word in DOuble CApitals to Single Capitals."
(interactive)
(and (= ?w (char-syntax (char-before)))
(save-excursion
(and (if (called-interactively-p 'any)
(skip-syntax-backward "w")
(= -3 (skip-syntax-backward "w")))
(let (case-fold-search)
(looking-at "\\b[[:upper:]]\\{2\\}[[:lower:]]"))
(capitalize-word 1)))))
(define-minor-mode sk/dubcaps-mode
"Toggle `sk/dubcaps-mode'. Converts words in DOuble CApitals to Single Capitals as you type."
:init-value nil
:lighter (" DC")
(if sk/dubcaps-mode
(add-hook 'post-self-insert-hook #'sk/dcaps-to-scaps nil 'local)
(remove-hook 'post-self-insert-hook #'sk/dcaps-to-scaps 'local)))
(add-hook 'text-mode-hook #'sk/dubcaps-mode)
(add-hook 'org-mode-hook #'sk/dubcaps-mode)
(add-hook 'python-mode-hook #'sk/dubcaps-mode)
(use-package go-translate
:straight t
:defer t
:bind
("C-c t" . gts-do-translate)
:custom
(gts-translate-list '(("en" "fr")))
(gts-default-translator
(gts-translator
:picker (gts-prompt-picker)
:engines (list (gts-google-engine :parser (gts-google-summary-parser)))
:render (gts-buffer-render)))
)
(defun narrow-or-widen-dwim (p)
"Widen if buffer is narrowed, narrow-dwim otherwise.
Dwim means: region, org-src-block, org-subtree, or
defun, whichever applies first. Narrowing to
org-src-block actually calls `org-edit-src-code'.
With prefix P, don't widen, just narrow even if buffer
is already narrowed."
(interactive "P")
(declare (interactive-only))
(cond ((and (buffer-narrowed-p) (not p)) (widen))
((region-active-p)
(narrow-to-region (region-beginning)
(region-end)))
((derived-mode-p 'org-mode)
;; `org-edit-src-code' is not a real narrowing
;; command. Remove this first conditional if
;; you don't want it.
(cond ((ignore-errors (org-edit-src-code) t)
(delete-other-windows))
((ignore-errors (org-narrow-to-block) t))
(t (org-narrow-to-subtree))))
((derived-mode-p 'latex-mode)
(LaTeX-narrow-to-environment))
(t (narrow-to-defun))))
(global-set-key (kbd "s-n") 'narrow-or-widen-dwim)
;; fichier en conf-mode
(add-to-list 'auto-mode-alist '("\\.orderedproperties\\'" . conf-mode))
(add-to-list 'auto-mode-alist '("\\.properties\\'" . conf-mode))
(add-to-list 'auto-mode-alist '("sudoers" . conf-mode))
(add-to-list 'auto-mode-alist '("offlineimaprc" . conf-mode))
(add-to-list 'auto-mode-alist '("cwclientlibrc" . conf-mode))
(use-package ssh-config-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("/\\.ssh/config\\'" . ssh-config-mode))
(add-to-list 'auto-mode-alist '("/sshd?_config\\'" . ssh-config-mode))
(add-to-list 'auto-mode-alist '("/known_hosts\\'" . ssh-known-hosts-mode))
(add-to-list 'auto-mode-alist '("/authorized_keys2?\\'" . ssh-authorized-keys-mode)))
(use-package vimrc-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '(".vim\\(rc\\)?$" . vimrc-mode)))
;; fichier en makefile-mode
(add-to-list 'auto-mode-alist '("\\makefile.*" . makefile-mode))
(add-to-list 'auto-mode-alist '("\\Makefile" . makefile-mode))
(use-package yasnippet
:straight t
:config
(use-package yasnippet-snippets :straight t)
(yas-global-mode t)
(setq yas/indent-line 'fixed)
;; pour avoir les snippet dans le minibuffer
(autoload 'yas-insert-snippet "dropdown-list" nil t)
(defadvice yas-insert-snippet (around use-completing-prompt activate)
"Use `yas/completing-prompt' for `yas/prompt-functions' but only here..."
(let ((yas-prompt-functions '(yas/completing-prompt))) ad-do-it))
(define-key yas-minor-mode-map (kbd "<tab>") nil) ;; pas sur tab
(define-key yas-minor-mode-map (kbd "TAB") nil) ;; pas sur tab
(global-set-key (kbd "<backtab>") 'yas-insert-snippet))
;; hs folding
(defun toggle-selective-display (column)
(interactive "P")
(set-selective-display
(or column
(unless selective-display
(1+ (current-column))))))
(defun toggle-hiding (column)
(interactive "P")
(if hs-minor-mode
(if (condition-case nil
(hs-toggle-hiding)
(error t))
(hs-show-all))
(toggle-selective-display column)))
;; raccourci
(global-set-key (kbd "C-<kp-add>") 'toggle-hiding)
(global-set-key (kbd "C-<kp-subtract>") 'toggle-hiding)
(use-package iedit
:straight t
:defer 1
:config
(global-set-key (kbd "C-;") 'iedit-mode)
(setq iedit-toggle-key-default nil) ;; pas les raccourcis iedit
)
(use-package rainbow-delimiters
:straight t
:defer 1
:hook (prog-mode . rainbow-delimiters-mode))
;;(setq tags-table-list (list "/home/giorgis/workspaces/MUSCLE-NG/"))
(use-package whitespace
:straight (:type built-in)
:config
(setq-default show-trailing-whitespace t)
(add-hook 'term-mode-hook (lambda() (setq show-trailing-whitespace nil)))
(add-hook 'eww-mode-hook (lambda() (setq show-trailing-whitespace nil)))
(add-hook 'logview-mode-hook (lambda() (setq show-trailing-whitespace nil)))
(add-hook 'calendar-mode-hook (lambda() (setq show-trailing-whitespace nil)))
(add-hook 'help-mode-hook (lambda() (setq show-trailing-whitespace nil))))
(use-package rainbow-mode :straight t)
(defalias 'color-mode 'rainbow-mode)
(add-to-list 'auto-mode-alist '("\\postBuild" . sh-mode))
(add-to-list 'auto-mode-alist '("\\activate" . sh-mode))
(use-package dumb-jump
:straight t
:config
(setq dumb-jump-prefer-searcher 'ag)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
(global-set-key (kbd "C-:") 'xref-find-definitions))
(use-package flycheck
:straight t
:config
(setq flycheck-pylintrc "/home/ogiorgis/.config/pylintrc")
(setq flycheck-pylint-use-symbolic-id nil) ;; ID pylint
(global-set-key (kbd "C-c <down>") 'flycheck-next-error)
(global-set-key (kbd "C-c <up>") 'flycheck-previous-error)
(global-set-key (kbd "C-c C-<down>") 'flycheck-next-error)
(global-set-key (kbd "C-c C-<up>") 'flycheck-previous-error)
;; smartrep
(smartrep-define-key
global-map "C-c"
'(("<down>" . flycheck-next-error)
("<up>" . flycheck-previous-error)))
;; flyspell in git commit
(defun flyspell-ignore-comments ()
"Used for 'flyspell-generic-check-word-predicate' to ignore comments."
(not (string-match "^ *#" (thing-at-point 'line t))))
(put 'git-commit-mode 'flyspell-mode-predicate 'flyspell-ignore-comments)
;; flyspell in markdown
(defun flyspell-generic-textmode-verify () ;; ignore code block
"Used for `flyspell-generic-check-word-predicate' in text modes."
(let ((f (get-text-property (- (point) 1) 'face)))
(not (memq f '(markdown-pre-face)))))
(setq flyspell-generic-check-word-predicate 'flyspell-generic-textmode-verify)
;; flyspell web-mode
(defun web-mode-flyspell-verify ()
(let ((f (get-text-property (- (point) 1) 'face))
thing
rlt)
(cond
((not (memq f '(web-mode-html-attr-value-face
web-mode-html-tag-face
web-mode-html-attr-name-face
web-mode-constant-face
web-mode-doctype-face
web-mode-keyword-face
web-mode-function-name-face
web-mode-variable-name-face
web-mode-css-property-name-face
web-mode-css-selector-face
web-mode-css-color-face
web-mode-type-face
web-mode-block-control-face)
))
(setq rlt t))
((memq f '(web-mode-html-attr-value-face))
(save-excursion
(search-backward-regexp "=['\"]" (line-beginning-position) t)
(backward-char)
(setq thing (thing-at-point 'symbol))
(setq rlt (string-match "^\\(value\\|class\\|ng[A-Za-z0-9-]*\\)$" thing))
rlt))
(t t))
rlt))
(put 'web-mode 'flyspell-mode-predicate 'web-mode-flyspell-verify)
;; restructure-text ??
(add-hook 'rst-mode-hook
(lambda ()
(setq-local flycheck-disabled-checkers '(rst-sphinx))
(setq-local flycheck-pycheckers-checkers '(rst))))
;; text
(add-hook 'text-mode-hook
(lambda ()
(setq flycheck-pycheckers-checkers '(proselint))))
)
(use-package company
:straight t
:init (add-hook 'after-init-hook #'global-company-mode)
:custom
(company-minimum-prefix-length 2)
(company-idle-delay 0.3)
(company-tooltip-limit 20)
(company-selection-wrap-around t)
(company-dabbrev-downcase nil)
(company-tooltip-align-annotations 't)
(company-transformers '(company-sort-by-occurrence))
(company-tooltip-maximum-width 300)
;; aligns annotation to the right hand side
(company-tooltip-align-annotations t)
:config
(setq company-backends '(company-capf
company-keywords
company-semantic
company-files
company-etags
company-elisp
company-cmake
company-ispell
company-yasnippet))
(setq company-frontends '(company-pseudo-tooltip-frontend
company-echo-metadata-frontend)))
;; company-dict
(use-package company-dict
:straight t
:after company
:config
(setq company-dict-dir (concat user-emacs-directory "dict/"))
(define-key org-mode-map (kbd "C-c <tab>") 'company-dict)
(define-key text-mode-map (kbd "C-c <tab>") 'company-dict))
(use-package prescient
:straight t
:after company
:hook (after-init . prescient-persist-mode))
;; no whitespace diff but context
(setq vc-diff-switches '("-b" "-B" "-u"))
(setq vc-git-diff-switches nil)
;; magit
(use-package dash :straight t :defer 1)
(use-package transient :straight t :defer 1)
(use-package with-editor :straight t :defer 1)
(use-package git-emacs :straight (:host github :repo "tsgates/git-emacs"))
(use-package magit
:straight t
:bind
("C-x g s" . magit-status)
("C-x g l" . magit-log-buffer-file)
:custom
(magit-keyboard-prefix (kbd "C-x g"))
(git-keyboard-prefix "\C-x£") ;; keybinding improbable (ie desactivation)
(magit-diff-options '("-b")) ;; ignore whitespace
(magit-push-always-verify nil)
(magit-commit-show-diff nil)
;; (magit-revert-buffers nil)
:config
;; modeline status
(autoload 'git--update-all-state-marks "git-modeline" "Update the modelines of all git buffers" t)
(add-hook 'find-file-hook 'git-status-in-modeline t)
(defun git-status-in-modeline ()
(if (and vc-mode (string-match "^ Git" (substring-no-properties vc-mode)))
(git--update-all-state-marks)))
;; vc-annotate v => affiche juste le nom su commiter
(eval-after-load "vc-annotate"
'(defun vc-annotate-get-time-set-line-props ()
(let ((bol (point))
(date (vc-call-backend vc-annotate-backend 'annotate-time))
(inhibit-read-only t))
(assert (>= (point) bol))
(put-text-property bol (point) 'invisible 'vc-annotate-annotation)
(when (string-equal "Git" vc-annotate-backend)
(save-excursion
(goto-char bol)
(search-forward "(")
(let ((p1 (point)))
(re-search-forward " [0-9]")
(remove-text-properties p1 (1- (point)) '(invisible nil))
)))
date)))
(remove-hook 'magit-refs-sections-hook 'magit-insert-tags)
;; (setq auto-revert-buffer-list-filter 'magit-auto-revert-repository-buffers-p)
(remove-hook 'server-switch-hook 'magit-commit-diff))
;; fichiers de conf
(use-package git-modes :straight t :defer 1)
;; ahg / monky
(use-package ahg
:straight t
:defer 1
:config
(global-unset-key (kbd "C-x m"))
(global-set-key (kbd "C-x m s") 'ahg-glog)
(global-set-key (kbd "C-x m h") 'ahg-glog-hidden)
(global-set-key (kbd "C-x m b") 'ahg-annotate-cur-file)
(global-set-key (kbd "C-x m =") 'ahg-diff-ediff-cur-file)
(global-set-key (kbd "C-x m l") 'ahg-log-cur-file)
(global-set-key (kbd "C-x m r") 'ahg-revert-cur-file)
;; mercurial status in modeline
(require 'hg-status)
(add-hook 'find-file-hook 'hg-status-in-modeline t)
(defun hg-status-in-modeline ()
(if (and vc-mode (string-match "^ Hg" (substring-no-properties vc-mode)))
(hg-status-update-modeline)))
)
(use-package diff-hl
:straight t
:defer 0.5
:custom
(diff-hl-fringe-bmp-function 'diff-hl-fringe-bmp-from-type)
:config
(global-diff-hl-mode)
(global-set-key (kbd "C-x <up>") 'diff-hl-previous-hunk)
(global-set-key (kbd "C-x <down>") 'diff-hl-next-hunk)
;; pour svn
(defadvice svn-status-update-modeline (after svn-update-diff-hl activate)
(diff-hl-update))
;; pour git
(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
;; diff-hl-flydiff
;;(require 'diff-hl-flydiff)
;;(diff-hl-flydiff-mode)
;; smartrep
(smartrep-define-key
global-map "C-x"
'(("<down>" . diff-hl-next-hunk)
("<up>" . diff-hl-previous-hunk)))
)
;; for xml files, use nxml-mode instead of sgml-mode
(setq auto-mode-alist
(cons '("\\.\\(xml\\|XML\\|xsd\\|XSD\\|xsl\\|prj\\|rng\\|xhtml\\|CR\\)\\'" . nxml-mode)
auto-mode-alist))
(defun my-nxml-hook ()
(use-package smart-tabs-mode :straight t)
(setq-default tab-width 4) ;; taille TAB
(smart-tabs-insinuate 'nxml)
(setq nxml-child-indent 4
nxml-attribute-indent 4
nxml-slash-auto-complete-flag t ;; auto completion
))
(add-hook 'nxml-mode-hook 'my-nxml-hook)
(defun nxml-where ()
"Display the hierarchy of XML elements the point is on as a path."
(interactive)
(let ((path nil))
(save-excursion
(save-restriction
(widen)
(while (condition-case nil
(progn
(nxml-backward-up-element) ; always returns nil
t)
(error nil))
(setq path (cons (xmltok-start-tag-local-name) path)))
(message "/%s" (mapconcat 'identity path "/"))
(kill-new (mapconcat 'identity path "/"))))))
(defun nxml-pretty-format ()
(interactive)
(save-excursion
(shell-command-on-region (point-min) (point-max) "xmllint --format -" (buffer-name) t)
(nxml-mode)
(indent-region begin end)))
;; controle des xml par xsd
(defun xsd-validation (xsd)
(interactive "f xsd: ")
(shell-command
(format "xmllint --noout %s --schema %s" (buffer-file-name) xsd)))
;; visualisation des xsd (en svg)
(defun xsd-show ()
(interactive)
(shell-command
(format "cd /tmp; java -jar ~/Tools/XSDVi/dist/lib/xsdvi.jar %s" (buffer-file-name)))
(shell-command
(format "firefox /tmp/%s" (concat (substring (file-name-nondirectory (buffer-file-name)) 0 -3) "svg"))))
;; generation xsd from xml
(defun xsd-generator ()
(interactive)
(shell-command
(format "java -jar ~/Tools/trang/trang.jar %s %s" (buffer-file-name) (concat (substring (buffer-file-name) 0 -3) "xsd")))
(find-file (concat (substring (buffer-file-name) 0 -3) "xsd")))
(use-package yaml-mode
:straight t
:config
(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)))
(use-package ldap-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.ldif$" . ldap-mode)))
(autoload 'csv-mode "csv-mode" "Major mode for editing comma-separated value files." t)
(setq csv-separators '("," ";" "|" "£" "\t"))
(add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode))
(add-to-list 'auto-mode-alist '("\\.dat\\'" . csv-mode))
;; affichage
(defun csv-pretty ()
(interactive)
(if (not (equal major-mode 'csv-mode))
(csv-mode))
(csv-align-fields nil (point-min) (point-max))
(toggle-truncate-lines t))
(global-set-key (kbd "C-c C-s") 'csv-pretty)
;; deplacement
(global-set-key (kbd "s-<tab>") 'csv-forward-field)
(global-set-key (kbd "s-<iso-lefttab>") 'csv-backward-field)
(autoload 'po-mode "po-mode" "Major mode for translators to edit PO files" t)
(setq auto-mode-alist (cons '("\\.po\\'\\|\\.po\\." . po-mode) auto-mode-alist))
(define-key emacs-lisp-mode-map (kbd "C-.") 'find-function)
;; indentation des commentaires (#) en bash
(setq sh-indent-comment t)
;; bash completion and check
(add-hook 'sh-mode-hook
(lambda ()
(setq flycheck-pycheckers-checkers '(sh-shellcheck))
(define-key sh-mode-map (kbd "C-<tab>") 'completion-at-point)))
;; association fichier bashrc
(add-to-list 'auto-mode-alist '("bashrc" . sh-mode))
;; Use archive mode to open Python eggs
(add-to-list 'auto-mode-alist '("\\.egg\\'" . archive-mode))
;; Use python-mode to open .pylintrc
(add-to-list 'auto-mode-alist '("\\pylintrc\\'" . python-mode))
;; fuzzy-format for this
(setq python-indent-guess-indent-offset nil)
(use-package fuzzy-format
:straight t
:config
(global-fuzzy-format-mode))
;; hook
(add-hook 'python-mode-hook
(lambda ()
;; yas
(global-set-key (kbd "<S-iso-lefttab>") 'yas-insert-snippet)
;; Python indentation
(setq tab-width 4)
(setq python-indent-offset 4)
(require 'flycheck-pycheckers) ;; config file ~/.pycheckers
(setq flycheck-pycheckers-ignore-codes '("C0411" "C0413" "W503"))
(with-eval-after-load 'flycheck
(add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup)
(defun flake8 ()
(interactive)
(if (bound-and-true-p flycheck-mode)
(progn
(setq flycheck-pycheckers-checkers '(flake8 pylint pep8))
(flycheck-mode -1))
(progn
(setq flycheck-pycheckers-checkers '(flake8))
(flycheck-mode))))
(defun pep8 ()
(interactive)
(if (bound-and-true-p flycheck-mode)
(progn
(setq flycheck-pycheckers-checkers '(flake8 pylint pep8))
(flycheck-mode -1))
(progn
(setq flycheck-pycheckers-checkers '(pep8))
(flycheck-mode))))
(defun pylint ()
(interactive)
(if (bound-and-true-p flycheck-mode)
(progn
(setq flycheck-pycheckers-checkers '(flake8 pylint pep8))
(flycheck-mode -1))
(progn
(setq flycheck-pycheckers-checkers '(pylint))
(flycheck-mode))))
)))
C-. => goto definition C-, => back s-? => Afficher la signature de la methode C-c d => jedi:show-doc Pour typer un parametre dans la doc “”” :type param: {} # the parameter :type baz: {str} # set of str :type quux: {str: [int]} “””
(use-package python-environment
:straight t
:config
(setq python-environment-directory "~/Tools/python/envs/"))
(use-package company-jedi
:straight t
:after company
:config
(add-to-list 'company-backends 'company-jedi)
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:complete-on-dot t)
(setq jedi:environment-root "python-emacs")
(setq jedi:tooltip-method (quote (nil)))
(setq jedi:tooltip-show nil)
;; goto-definition
(setq jedi:goto-definition-config
'((nil definition nil)
(t definition nil)
(nil nil nil)
(t nil nil)
(nil definition t )
(t definition t )
(nil nil t )
(t nil t )))
(define-key python-mode-map (kbd "C-.") 'jedi:goto-definition)
(define-key python-mode-map (kbd "C-,") 'jedi:goto-definition-pop-marker)
(define-key python-mode-map (kbd "s-?") 'jedi:get-in-function-call)
(define-key python-mode-map (kbd "C-s-?") 'jedi:show-doc))
(use-package python-docstring
:straight t
:config
(add-hook 'python-mode-hook (lambda () (python-docstring-mode t))))
;;(setq gud-pdb-command-name "~/Outils/pdb/pdb.py")
;; Surligne les mots temporaires pdb, ipdb,
(defun annotate-keywords ()
(interactive)
(let ((case-fold-search nil))
(highlight-lines-matching-regexp "import ipdb")
(highlight-lines-matching-regexp "import pdb")
(highlight-lines-matching-regexp "set_trace()")
(highlight-regexp "TODO")
(highlight-regexp "FIXME")
(highlight-regexp "XXX")
(highlight-regexp "OLIV")))
(add-hook 'python-mode-hook 'annotate-keywords)
(use-package pyvenv
:straight t
:config
(pyvenv-activate "/home/ogiorgis/Tools/python/envs/python-emacs")
(defalias 'switch-virtualenv 'pyvenv-workon))
(use-package pip-requirements
:straight t
:config
(add-to-list 'auto-mode-alist '("\\requires.txt\\'" . pip-requirements-mode)))
(defun pyqt-browser ()
(interactive)
(eww "http://pyqt.sourceforge.net/Docs/PyQt4/classes.html"))
(use-package ini-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.ini\\'" . ini-mode)))
(use-package cython-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.pyx\\'" . cython-mode))
(add-to-list 'auto-mode-alist '("\\.pxd\\'" . cython-mode))
(add-to-list 'auto-mode-alist '("\\.pxi\\'" . cython-mode))
)
(use-package blacken
:defer 1
:straight (:host github :repo "proofit404/blacken")
:config
(setq blacken-executable "/home/ogiorgis/.local/bin/black")
(setq blacken-line-length 79)
)
(if (version< "27.0" emacs-version)
(setq python-font-lock-keywords-maximum-decoration
(append python-font-lock-keywords-maximum-decoration
'(;; this is the full string.
;; group 1 is the quote type and a closing quote is matched
;; group 2 is the string part
("f\\(['\"]\\{1,3\\}\\)\\(.+?\\)\\1"
;; these are the {keywords}
("{[^}]*?}"
;; Pre-match form
(progn (goto-char (match-beginning 0)) (match-end 0))
;; Post-match form
(goto-char (match-end 0))
;; face for this match
(0 font-lock-variable-name-face t)))))))
(use-package rust-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)))
(c-set-offset 'innamespace 0)
(use-package modern-cpp-font-lock
:straight t
:defer 1
:config
(modern-c++-font-lock-global-mode t))
(use-package clang-format :straight t)
(ede-cpp-root-project :name "Code Tympan"
:file "/home/ogiorgis/workspaces/Tympan/code_tympan_gitlab/Tympan/CMakeLists.txt"
:include-path '("/Tympan/core/"
"/Tympan/geometric_methods/AcousticRaytracer"
"/Tympan/geometric_methods/AnalyticRayTracer"
"/Tympan/geometric_methods/ConvexHullFinder"
"/Tympan/gui/"
"/Tympan/gui/app"
"/Tympan/gui/gl"
"/Tympan/gui/tools"
"/Tympan/gui/widgets"
"/Tympan/models/business"
"/Tympan/models/business/acoustic"
"/Tympan/models/business/geoacoustic"
"/Tympan/models/business/geometry"
"/Tympan/models/business/infrastructure"
"/Tympan/models/business/material"
"/Tympan/models/business/topography"
"/Tympan/models/common"
"/Tympan/models/solver"
"/Tympan/solvers/ANIME3DSolver"
"/Tympan/solvers/ConvexHullFinder"
"/Tympan/solvers/DefaultSolver")
:system-include-path '("/usr/include/c++/3.6.0/ /usr/include/boost/")
:spp-table '(("isUnix" . "") ("BOOST_TEST_DYN_LINK" . "")))
(defun my-cedet-hook ()
;; indentation
(require 'google-c-style)
(google-set-c-style)
(setq c++-tab-always-indent t
indent-tabs-mode t
c-basic-offset 4 ;; Default is 2
c-indent-level 4) ;; Default is 2
;; semantic
(global-set-key (kbd "s-<tab>") 'semantic-ia-complete-symbol-menu)
(global-set-key (kbd "C-c ?") 'semantic-ia-complete-symbol)
(global-set-key (kbd "M-s-<tab>") 'semantic-complete-analyze-inline)
(global-set-key (kbd "M-i") 'semantic-decoration-include-visit)
(global-set-key (kbd "C-.") 'xref-find-definition)
(global-set-key (kbd "C-c d") 'semantic-ia-show-doc)
(global-set-key (kbd "C-,") 'dumb-jump-back)
(global-set-key (kbd "C-M-:") 'semantic-complete-jump)
(global-set-key (kbd "C-:") 'semantic-complete-jump-local)
(global-set-key (kbd "C-c s") 'semantic-ia-show-summary)
(global-set-key (kbd "C-c c") 'semantic-ia-describe-class)
(global-set-key (kbd "C-c B") 'semantic-ia-fast-jump-back)
;; deplacement de function en function
(global-set-key (kbd "M-s-<left>") 'senator-previous-tag)
(global-set-key (kbd "M-s-<right>") 'senator-next-tag)
(setq c-hungry-delete-key t)
(global-set-key (kbd "s-;") 'semantic-symref)
(global-set-key (kbd "s-:") 'semantic-symref-symbol)
;; folding
(global-set-key (kbd "C-<kp-subtract>") 'senator-fold-tag)
(global-set-key (kbd "C-<kp-add>") 'senator-unfold-tag)
;; company
(use-package company-c-headers :straight t)
(add-to-list 'company-backends 'company-c-headers)
(add-to-list 'company-c-headers-path-system "/usr/include/c++/4.4.7/ /usr/include/boost/")
)
(add-hook 'c++-mode-hook 'my-cedet-hook)
(defun my-c-mode-common-hook ()
;; eassist
(require 'eassist) ;; M-o M-m
;; function-args
(use-package function-args :straight t)
;;(fa-config-default) ;; M-i M-j
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
;; eassist
(setq eassist-header-switches '(("h" . ("cpp" "cc" "c" "cxx"))
("hpp" . ("cpp" "cc" "cxx"))
("hh" . ("cc" "cxx"))
("cpp" . ("h" "hpp"))
("cxx" . ("h" "hpp"))
("c" . ("h"))
("C" . ("H"))
("H" . ("C" "CPP" "CC" "CXX"))
("cc" . ("h" "hpp" "hh"))))
(global-set-key (kbd "M-o") 'eassist-switch-h-cpp)
;; You can add this to improve the parse of macro-heavy code:
(require 'semantic/bovine/c)
(add-to-list 'semantic-lex-c-preprocessor-symbol-file "/usr/lib/gcc/x86_64-linux-gnu/6.3.0/include/stddef.h")
)
(add-hook 'c++-mode-hook 'my-c-mode-common-hook)
;; Ferme la fenetre de compil si pas d'erreur
(defun compilation-exit-autoclose (status code msg)
;; If M-x compile exists with a 0
(if (and (eq status 'exit) (zerop code))
(progn
;; then bury the *compilation* buffer, so that C-x b doesn't go there
(bury-buffer)
;; and delete the *compilation* window
(delete-window (get-buffer-window (get-buffer "*compilation*"))))
(other-window 1))
;; Always return the anticipated result of compilation-exit-message-function
(cons msg code))
;; Specify my function (maybe I should have done a lambda function)
(setq compilation-exit-message-function 'compilation-exit-autoclose)
;; member-function
(autoload 'expand-member-functions "member-functions" "Expand C++ member function declarations" t)
(add-hook 'c++-mode-hook (lambda () (global-set-key (kbd "C-c m") 'expand-member-functions)))
;; find-tag
(global-set-key (kbd "s-.") 'find-tag-other-window)
;; tag suivant
(defun find-tag-next ()
(interactive)
(let ((current-prefix-arg 4))
(call-interactively 'find-tag)))
(global-unset-key (kbd "M-,"))
(global-set-key (kbd "M-,") 'find-tag-next)
;; sexp deplacement
(defun forward-or-backward-sexp (&optional arg)
"Go to the matching parenthesis character if one is adjacent to point."
(interactive "^p")
(cond ((looking-at "\\s(") (forward-sexp arg))
((looking-back "\\s)" 1) (backward-sexp arg))
;; Now, try to succeed from inside of a bracket
((looking-at "\\s)") (forward-char) (backward-sexp arg))
((looking-back "\\s(" 1) (backward-char) (forward-sexp arg))))
(global-set-key (kbd "C-%") 'forward-or-backward-sexp)
(global-set-key (kbd "S-<right>") 'forward-sexp)
(global-set-key (kbd "S-<left>") 'backward-sexp)
(global-set-key (kbd "S-<up>") 'beginning-of-defun)
(global-set-key (kbd "S-<down>") 'end-of-defun)
;; for org-mode
(define-key org-mode-map (kbd "S-<right>") 'forward-sexp)
(define-key org-mode-map (kbd "S-<left>") 'backward-sexp)
(use-package cmake-mode
:straight t
:defer 1
:config
(setq auto-mode-alist
(append '(("CMakeLists\\.txt\\'" . cmake-mode)
("\\.cmake\\'" . cmake-mode)) auto-mode-alist)))
(add-to-list 'auto-mode-alist '("\\.f\\'" . f90-mode))
(use-package ess
:straight t
:commands ess-site)
(use-package salt-mode :straight t :defer 1)
(use-package groovy-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("Jenkinsfile" . groovy-mode)))
(use-package kotlin-mode
:straight t
:defer
:config
(add-to-list 'auto-mode-alist '("\\.kt\\'" . kotlin-mode)))
(use-package jquery-doc
:straight t
:defer 1
:config
(add-hook 'js2-mode-hook 'jquery-doc-setup))
;; javascript
(use-package json-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.ipynb$" . json-mode))
(add-to-list 'auto-mode-alist '("\\.json$" . json-mode)))
(use-package js2-mode
:straight t
:defer 1
:config
(setq js-indent-level 2)
(add-hook 'js2-mode-hook
(lambda ()
;; doubleclick selection
(define-key js2-mode-map [mouse-1] 'mouse-set-point)
;; goto definition
(define-key js2-mode-map (kbd "C-.") 'js2-jump-to-definition))
;; company
(delq 'company-etags company-backends))
(add-hook 'js2-mode-hook
(lambda ()
(require 'flycheck)
;; disable jshint since we prefer eslint checking
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint)))
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(json-jsonlist)))
;; use eslint with web-mode and javascript-mode
(flycheck-add-mode 'javascript-eslint 'web-mode)
(flycheck-add-mode 'javascript-eslint 'js2-mode))
)
)
(use-package tide
:straight t
:config
(defun setup-tide-mode ()
(interactive)
(tide-setup)
(flycheck-mode +1)
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(global-set-key (kbd "C-.") 'tide-jump-to-definition)
(tide-hl-identifier-mode +1))
(add-hook 'web-mode-hook
(lambda ()
(when (or (string-equal "tsx" (file-name-extension buffer-file-name)) (string-equal "ts" (file-name-extension buffer-file-name)))
(setq prettier-js-args '( ))
(prettier-js-mode)
(setq web-mode-enable-auto-indentation nil)
(setup-tide-mode))))
(add-hook 'web-mode-hook
(lambda ()
(when (string-equal "jsx" (file-name-extension buffer-file-name))
(setq prettier-js-args '(
"--trailing-comma" "all"
"--semi" "false"
"--single-quote" "true"
"--tab-width" "4"
"--bracket-spacing" "false"
"--arrow-parens" "avoid"
))
(prettier-js-mode)
(setq web-mode-enable-auto-indentation nil)
(setup-tide-mode))))
(flycheck-add-mode 'typescript-tslint 'web-mode))
(add-to-list 'auto-mode-alist '("\.ts\'" . web-mode))
;; company
(use-package ac-html-bootstrap :straight t)
(use-package company-web
:straight t
:after company
:config
(global-set-key (kbd "C-<tab>") 'company-complete)
(add-hook 'web-mode-hook
(lambda ()
(add-to-list 'company-backends 'company-nxml)
(add-to-list 'company-backends 'company-web-html)
(add-to-list 'company-backends 'company-css)
)))
(use-package web-mode
:straight t
:mode (("\\.tsx$" . web-mode)
("\\.html$" . web-mode)
("\\.phtml$" . web-mode)
("\\.djhtml$" . web-mode)
("\\.jinja$" . web-mode)
("\\.jinja2$" . web-mode)
("\\.php$" . web-mode)
("\\.jsp$" . web-mode)
("\\.as[cp]x\\'" . web-mode)
("\\.jsx$" . web-mode)
("\\.mako\\'" . web-mode)
("\\.ts$" . web-mode)
("\\.tpl$" . web-mode)
("\\.css$" . web-mode)
("\\.scss$" . web-mode))
:custom
(web-mode-auto-close-style 1)
(web-mode-tag-auto-close-style t)
(web-mode-enable-auto-pairing t)
(web-mode-enable-auto-indentation t)
(web-mode-enable-indent-cycle t)
(web-mode-enable-auto-quoting nil)
:config
;; hook
(add-hook 'web-mode-hook
(lambda ()
;; indentation
(setq indent-tabs-mode nil)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2)
;; padding
(setq web-mode-style-padding 1)
(setq web-mode-script-padding 1)
(setq web-mode-block-padding 0)
;; raccourcis
(define-key web-mode-map (kbd "M-;") 'web-mode-comment-or-uncomment)
(define-key web-mode-map (kbd "M-k") 'web-mode-element-kill)
(define-key web-mode-map (kbd "C-c C-v") 'browse-url-of-buffer) ;; preview
))
;; force django engine for html
(setq web-mode-engines-alist
'(("django" . "\\.html\\'")
("jinja" . "\\.jinja\\'")
("jinja" . "\\.jinja2\\'"))
)
;; force django engine (manual)
(defun web-mode-django ()
(interactive)
(web-mode-set-engine "django"))
(global-set-key (kbd "s-%") 'web-mode-django)
;; force angular engine (manual)
(defun web-mode-angularJs ()
(interactive)
(web-mode-set-engine "angular")))
(use-package less-css-mode
:straight t
:config
(add-to-list 'auto-mode-alist '("\\.less$" . less-css-mode))
(add-hook 'less-css-mode-hook 'rainbow-mode)
(add-hook 'css-mode-hook 'rainbow-mode))
(use-package elm-mode
:straight t
:defer 1
:config
(setq elm-format-on-save t)
(add-to-list 'auto-mode-alist '("\\.eml\\'" . org-mode)))
(use-package apache-mode
:straight t
:config
(add-to-list 'auto-mode-alist '("\\.htaccess\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("httpd\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("srm\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("access\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("sites-\\(available\\|enabled\\)/" . apache-mode)))
(use-package restclient
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.restclient$" . restclient-mode))
(setq url-proxy-services '(("no_proxy" . "^\\(localhost\\|127.*\\|10.*\\)"))))
(use-package nginx-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("default_site" . nginx-mode)))
(use-package dockerfile-mode
:straight t
:defer t
:config
(add-to-list 'auto-mode-alist '("\\Dockerfile*" . dockerfile-mode)))
(use-package docker-compose-mode :straight t :defer 1)
;; SPARQL
(use-package sparql-mode
:straight t
:defer 1
:config
(add-to-list 'auto-mode-alist '("\\.sparql$" . sparql-mode))
(add-hook 'sparql-mode-hook 'company-completion-mode))
;; RQL
(use-package rql-mode
:straight (:host github :repo "hmadison/rql-mode")
:defer 1
:config
;; Turtle RDF
(autoload 'n3-mode "n3-mode" "Major mode for OWL or N3 files" t)
;; Turn on font lock when in n3 mode
(add-hook 'n3-mode-hook 'turn-on-font-lock)
(setq auto-mode-alist
(append
(list
'("\\.n3" . n3-mode)
'("\\.owl" . n3-mode))
auto-mode-alist)))
;; (require 'eswap-mode)
;; (eswap-global-mode t)
;; (setq eswap-toggle-path-alist ;; (srcPath . targetPath )
;; (quote
;; (("/space/giorgis/workspaces/AGILE/trunk/agile-traitements/src/main/python/" . "/AGILE/SAG_vm-agile02/OPERATIONNEL/REFERENTIEL_AGILE/TRAITEMENTS/")
;; ("/space/giorgis/workspaces/AGILE/trunk/agile-traitements/src/main/config/" . "/AGILE/SAG_vm-agile02/OPERATIONNEL/REFERENTIEL_AGILE/CONFIG/")
;; ("/space/giorgis/workspaces/AGILE/trunk/agile-traitements/src/main/script" . "/AGILE/SAG_vm-agile02/OPERATIONNEL/REFERENTIEL_AGILE/SCRIPTS")
;; ("/space/giorgis/workspaces/TEC-S2/trunk/tecs2-traitements/src/main/python/TEC_TRAITEMENTS/" . "/AGILE/SAG_vm-agile02/OPERATIONNEL/REFERENTIEL_TECS2/TRAITEMENTS/TEC_TRAITEMENTS/")
;; ("/space/giorgis/workspaces/4ARTIC/trunk/src/Main" . "/space/giorgis/dev/4ARTIC/install/Main")
;; ("/space/giorgis/workspaces/4ARTIC/trunk/src/Input" . "/space/giorgis/dev/4ARTIC/install/Input")
;; ("/space/giorgis/workspaces/4ARTIC/trunk_preprocessing/src/Main/" . "/space/giorgis/dev/4ARTIC/install_preproc/Main/")
;; ("/space/giorgis/workspaces/4ARTIC/trunk_preprocessing/src/Input/" . "/space/giorgis/dev/4ARTIC/install_preproc/Input/")
;; ("/space/giorgis/workspaces/4ARTIC/trunk_preprocessing/ressources/" . "/space/giorgis/dev/4ARTIC/install_preproc/ressources/")
;; ("/space/giorgis/workspaces/4ARTIC/trunk/ressources" . "/space/giorgis/dev/4ARTIC/install/ressources")
;; ("/home/giorgis/.emacs.d/" . "/space/giorgis/Outils/github/conf")
;; ("/home/giorgis/.emacs.d/lisp" . "/space/giorgis/Outils/github/org-week-tracker")
;; )))
;; open-template
(defun open-template (format)
(interactive "sformat: ")
(find-file (concat "~/.emacs-templates/temp." format)))
(defun tail ()
(interactive)
(auto-revert-tail-mode))
;; somme rectangle
(defun sum-column (start end)
"Adds numbers in a rectangle"
(interactive "r")
(copy-rectangle-to-register 9 start end)
(set-buffer (get-buffer-create "*calc-sum*"))
(erase-buffer)
(insert-register 9)
(let ((sum 0))
(while (re-search-forward "[0-9]*\\.?[0-9]+" nil t)
(setq sum (+ sum (string-to-number (match-string 0)))))
(message "Sum: %f" sum)))
;; list colors and switch
(defun list-colors ()
(interactive)
(list-colors-display)
(select-window (get-buffer-window "*Colors*")))
;; tri avec respect des accents et majuscules
(defun my-sort-lines-buffer ()
(interactive)
(shell-command-on-region (point-min) (point-max) "LC_COLLATE=en_US.UTF-8 sort" (buffer-name) t ))
(defun my-sort-lines-region (start end)
(interactive "r")
(shell-command-on-region start end "LC_COLLATE=en_US.UTF-8 sort" (buffer-name) t))
(defun my-sort-lines-region-or-buffer ()
(interactive)
(save-excursion
(if (region-active-p)
(progn
(my-sort-lines-region (region-beginning) (region-end))
(message "Sorted selected region"))
(progn
(my-sort-lines-buffer)
(message "Sorted buffer")))))
;; delete enclose text
;; returns the enclosing character for the character "c"
(defun get-enc-char (c) (cond
((string= c "(") ")")
((string= c "[") "]")
((string= c "{") "}")
((string= c ">") "<")
((string= c "<") ">")
((string= c "'") "'")
((string= c "\"") "\"")
(t nil)
))
(defvar empty-enclose 0)
(defun delete-enclosed-text ()
"Delete texts between any pair of delimiters."
(interactive)
(setq empty-enclose 0)
(save-excursion
(let (p1 p2 orig)
(setq orig (point))
(setq p1 (point))
(setq p2 (point))
(setq find 0)
(setq mychar (thing-at-point 'char))
(if (-contains? '("(" "[" "{" "<" "'" "\"") mychar)
(progn
(setq left_encloser (thing-at-point 'char))
(backward-char -1)
(if (string-equal (thing-at-point 'char) (get-enc-char left_encloser))
(progn
(backward-char -1)
(setq p2 (point))
(setq find 1)
(setq empty-enclose 1)))))
(while (eq find 0)
(skip-chars-backward "^({[<>\"'")
(setq p1 (point))
(backward-char 1)
(setq left_encloser (thing-at-point 'char))
(goto-char orig)
(while (and (not (eobp)) (eq find 0))
(backward-char -1)
(skip-chars-forward "^)}]<>\"'")
(setq right_encloser (thing-at-point 'char))
(if (string-equal right_encloser (get-enc-char left_encloser))
(progn
(setq p2 (point))
(setq find 1))))
(goto-char p1)
(backward-char 1))
(delete-region p1 p2)))
(if (eq empty-enclose 0)
(backward-char 1)))
(global-set-key (kbd "s-<delete>") 'delete-enclosed-text)
;; A list of opposite boolean pairs.
(defvar bools '(("true" . "false") ("True" . "False") ("TRUE" . "FALSE") ("#t" . "#f") ("yes" . "no") ("Yes" . "No") ("YES" . "NO")))
(defun flip-bool-at-point ()
"Flips the boolean literal at point, changing true to false and vice-versa."
(interactive)
(let* ((true (cdr (assoc (current-word) bools)))
(false (car (rassoc (current-word) bools)))
(wrd (cond (true true)
(false false)
(t (current-word)))))
(save-excursion
(forward-word)
(backward-kill-word 1)
(insert wrd))))
(global-set-key (kbd "C-c b") 'flip-bool-at-point)
(setq initial-scratch-message "
;; ,---,
;; ,`--,' |
;; ,---, ,--, | : :
;; ,' ,' `. ,--,'| ,--, | | '
;; ,---,' `. ,--, ,---, ,---, | | : ,--,'| ' : |
;; | | /`. |,--,/| ,---, / | ,----,_,, ' ,'` : : ' | |, ,---,; |,'
;; : : | : || |/ ,--,--, ,--,'|' | / / ' / / / || ' | '--'_ /, ,/|'---'
;; | : : ; :'--`_ / ` | | ,-' || : |, ; ,, :' | | ,' ,'| ,-' , ' |
;; : | ; : |,--,'| ,--, ,-, | | | / | || | ,` ,' | |: :| | : ' | |/___/ `: |
;; | | : | '| | ' `__`/: , , | | | | |, ; '; |' | ,; :' : |__ | | :, ` ' ,
;; : : | / ; : | | ,' ,--,; | | | | |/ ' , , || : || | ','|' : |_` ` '
;; | | '` ,/__| : ' / / ,, | | | |--' `---`-'| | ` ` / ; : ;| | ','` ` |
;; ; : ,','__/-_: |; : ,' `| |/ ,'__/`_: | '----' | , / ; : ;` ` |
;; | ,,' | : :| , ,-,/'---' | : : ---`-' | , / '---'
;; '---' ` : / '--*---' ` | / ---`-'
;; `--`-' `--`-'")
(autoload 'org-week-tracker-goto-current-entry "org-week-tracker" nil t)
(setq org-week-tracker-exclude-day-list '(0 6)) ;; exclude day 0=sunday 6=saturday
(setq org-week-tracker-file "~/.emacs-org/time-tracker.org")
(global-set-key (kbd "s-<end>") 'org-week-tracker-goto-current-entry)
(autoload 'pyutils-mode "pyutils" "python extend" t)
(add-hook 'python-mode-hook '(lambda ()
(pyutils-mode)
(define-key python-mode-map (kbd "<f8>") 'pyutils-shebang-insert)
(define-key python-mode-map (kbd "s-w") 'pyutils-where)))
;; emacs customize conf
(setq custom-file "~/.emacs.d/lisp/custom.el")
(load custom-file 'noerror)
;; server
(server-start)
;; declare cette frame comme la princiale (pour emacsclient)
(setq server-window (selected-frame))
;; enleve le message de confirmation "Buffer `blah' still has clients; kill it? (yes or no)"
(remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
;; plus rien a degugger
(setq debug-on-error nil)
;; start page
(setq initial-buffer-choice "~/.emacs-org/memo.org")
;; =================== etags =====================
(defvar tags-cmd "etags -R ./* 2>/dev/null")
(defun regen-tags ()
"Regenerate the tags file for the current working directory"
(interactive)
(let ((tag-file (concat default-directory "TAGS")))
(shell-command tags-cmd)
(visit-tags-table tag-file)))
;; =================== end etags =====================
(defun enable-clipboard()
(interactive)
;;(setq x-select-enable-clipboard t)
(setq select-enable-clipboard t)
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value))
;; google agenda
(defun google-agenda-open ()
"Open my google calendar agenda file. The agenda is displayed in the buffer *gcal*."
(interactive)
;; launch gcalcli
(shell-command "python2 /usr/bin/gcalcli --nostarted agenda > /tmp/gagenda")
;; set name of calendar buffer and location of file containing my agenda
(let ((tmp-buff-name "*gcal*") (cal-file (expand-file-name "/tmp/gagenda")))
;; switch to calendar buffer
(switch-to-buffer tmp-buff-name)
;; turn off read only to overwrite if buffer exists
(read-only-mode -1)
;; clear buffer
(erase-buffer)
;; insert agenda file
(insert-file-contents cal-file)
;; turn on special mode
(special-mode)
;; turn off line wrapping
(visual-line-mode -1)))
;; (use-package company-box
;; :straight t
;; :defer 1
;; :config
;; (add-hook 'company-mode-hook 'company-box-mode)
;; (dimmer-configure-company-box)
;; (setq company-tooltip-minimum-width 70)
;; (setq company-tooltip-maximum-width
(use-package company-quickhelp
:straight t
:defer 1
:config
(company-quickhelp-mode))
(use-package eaf
:straight t
:load-path "~/.emacs.d/straight/repos/eaf/"
:init
(use-package ctable :straight t :defer t)
(use-package deferred :straight t :defer t)
(use-package s :straight t :defer t)
:custom
(eaf-browser-continue-where-left-off t))
(setq sql-sqlite-options '("-interactive"))