Commit 7e8a667b authored by maliky's avatar maliky
Browse files

Initial commit

parents
Add this to your .bashrc file
#+BEGIN_SRC bash
# don't put duplicate lines or lines starting with space in the history, and erase duplicates
HISTCONTROL=ignoreboth:erasedups
HISTSIZE=5000
HISTFILESIZE=10000
HISTTIMEFORMAT="%Y-%m-%d %H:%M "
# append to the history file, don't overwrite it
shopt -s histappend
#+END_SRC
With a call to the script log_persistent_history.sh
The scripts use a second history file to save your history accross terminals
#+BEGIN_SRC bash
ph_file="$HOME/.persistent_history"
if [ -f ~/bin/log_persistent_history.sh ]; then
. ~/bin/log_persistent_history.sh
PROMPT_COMMAND="log_persistent_history"
else
PROMPT_COMMAND=
fi
#+END_SRC
Add this to your .bashrc file
# don't put duplicate lines or lines starting with space in the history, and erase duplicates
HISTCONTROL=ignoreboth:erasedups
HISTSIZE=5000
HISTFILESIZE=10000
HISTTIMEFORMAT="%Y-%m-%d %H:%M "
# append to the history file, don't overwrite it
shopt -s histappend
With a call to the script log<sub>persistent</sub><sub>history.sh</sub>
The scripts use a second history file to save your history accross terminals
ph_file="$HOME/.persistent_history"
if [ -f ~/bin/log_persistent_history.sh ]; then
. ~/bin/log_persistent_history.sh
PROMPT_COMMAND="log_persistent_history"
else
PROMPT_COMMAND=
fi
#+PROPERTY: header-args :tangle yes :results silent :session init
# C-c C-v t --> to tangle
* update load path
#+BEGIN_SRC emacs-lisp
;;;; Update load path
(add-to-list 'load-path "~/.emacs.d/elpa")
(add-to-list 'load-path "~/.emacs.d/plugins/auctex")
(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet")
(add-to-list 'load-path "~/.emacs.d/elpa/org-mode")
(add-to-list 'load-path "~/.emacs.d/elpa/org-plus-contrib")
(add-to-list 'load-path "~/.emacs.d/elpa/ob-ipython")
(add-to-list 'load-path "~/.emacs.d/elpa/s") ;; ess related
(add-to-list 'load-path "~/.emacs.d/elpa/dash")
(add-to-list 'load-path "~/.emacs.d/elpa/f")
(add-to-list 'load-path "~/.emacs.d/elpa/dash-functional")
; (add-to-list 'load-path "~/.emacs.d/plugins/ESS/lisp/")
; (add-to-list 'load-path "~/.emacs.d/plugins")
(load-file "~/.emacs.d/elpa/graphviz-dot-mode-20171103.127/graphviz-dot-mode.el")
#+END_SRC
* Emacs package system
#+BEGIN_SRC emacs-lisp
;;;; emacs package system
(require 'package)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")
("org" . "http://orgmode.org/elpa/")))
(package-initialize)
#+END_SRC
* Requirements
#+BEGIN_SRC emacs-lisp
;;;; Requirements
(require 'iso-transl)
(require 'package)
; (require 'hide-comnt) ; to hide comment in hs mode ?
;;;; org-exporter
(require 'ox-beamer)
(require 'ox-freemind)
(require 'ob-ipython)
(require 'ein)
(require 'ein-loaddefs)
(require 'ein-notebook)
(require 'ein-subpackages)
; (require 'ess-site)
;(load "ess-site")
#+END_SRC
* Backup and autosave
#+BEGIN_SRC emacs-lisp
(defvar backup-dir (expand-file-name "~/.emacs.d/backup/"))
(defvar autosave-dir (expand-file-name "~/.emacs.d/auto-save-list/"))
(setq backup-directory-alist (list (cons ".*" backup-dir)))
(setq auto-save-list-file-prefix autosave-dir)
(setq auto-save-file-name-transforms `((".*" ,autosave-dir t)))
#+END_SRC
* AUCTex et lacheck
#+BEGIN_SRC emacs-lisp
;;;; AUCTex et lacheck
(setq TeX-PDF-mode t) ; will compile pdf by default.
(setq TeX-auto-local (expand-file-name "~/.emacs.d/plugins/auctex/style-auto-parse/"))
(setq TeX-auto-save t)
(setq TeX-parse-self t)
; (setq-default TeX-master nil)
; bind C-c = to the toc of my latex document
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
#+END_SRC
* Yasnippet
#+BEGIN_SRC emacs-lisp
;;;; Yasnippet
(add-hook 'asy-mode
#'(lambda ()
(yas-activate-extra-mode 'asy-mode)))
(add-hook 'graphviz-dot-mode
#'(lambda ()
(yas-activate-extra-mode graphviz-dot-mode)))
#+END_SRC
* Org Mode
#+BEGIN_SRC emacs-lisp
;;;; Org Mode
(defun org-show-current-heading-tidily ()
(interactive) ; Interactive
"Show next entry, keeping other entries closed."
(if (save-excursion (end-of-line) (outline-invisible-p))
(progn (org-show-entry) (show-children))
(outline-back-to-heading)
(unless (and (bolp) (org-on-heading-p))
(org-up-heading-safe)
(hide-subtree)
(error "Boundary reached"))
(org-overview)
(org-reveal t)
(org-show-entry)
(show-children)))
;;;; Making sure org basic cmd are accessible everywhere
;; (global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
;; (global-set-key "\C-cc" 'org-capture)
;; (global-set-key "\C-cb" 'org-iswitchb)
#+END_SRC
Dans la fonction suivante, il faut vérifier les \ dans l'expression régulière
#+BEGIN_SRC emacs-lisp
;; (defun mlk-latex-filter-nobreaks (text backend info) "Ensure \"~\"
;; are properly handled in LaTeX export." (when
;; (org-export-derived-backend-p backend 'latex)
;; (replace-regexp-in-string "\\textasciitilde{}" "~" text)))
;; (add-to-list 'org-export-filter-plain-text-functions
;; 'my-latex-filter-nobreaks)
#+END_SRC
** Org Babel
Check the guy at https://github.com/gregsexton/ob-ipython
#+BEGIN_SRC emacs-lisp
;;;; set code langages
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(ipython . t)
(asymptote . t)
(R . t)
(latex . t)
(ein . t)
(dot . t)
))
; 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)
#+END_SRC
#+RESULTS:
| org-display-inline-images |
*** Latex-export for csedu class (ox-latex export)
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-latex-classes '("csedu"
"\\documentclass[a4paper,twoside]{article}
[NO-DEFAULT-PACKAGES]
\\usepackage{subfigureThen}
\\usepackage{calc}
\\usepackage{amssymb}
\\usepackage{amstext}
\\usepackage{amsmath}
\\usepackage{amsthm}
\\usepackage{multicol}
\\usepackage{pslatex}
% added packages
\\usepackage{natbib}
\\usepackage[T1]{fontenc}
\\usepackage[utf8]{inputenc}
\\usepackage[english]{babel}
\\usepackage[xindy,acronym]{glossaries}
\\usepackage{graphicx}
[EXTRA]
\\usepackage{SCITEPRESS} % Please add other packages that you may need BEFORE the SCITEPRESS.sty package.
"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
#+END_SRC
* Modes
electric-pair-mode is a minor mode shiped with emacs
#+BEGIN_SRC emacs-lisp
;;;; More Modes
; (add-hook 'text-mode-hook 'hs-minor-mode)
(electric-pair-mode 1)
#+END_SRC
** EIN
#+BEGIN_SRC emacs-lisp
(setq
ein:jupyter-default-server-command "/usr/local/bin/jupyter")
(setq ein:jupyter-server-args (list "--no-browser"))
#+END_SRC
* Emacs customization
#+BEGIN_SRC emacs-lisp
;; If there is more than one, they won't work right.
(custom-set-variables
'(tool-bar-mode nil) ;; pour ne pas voir s'afficher la tool bar
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#e090d7" "#8cc4ff" "#eeeeec"])
'(custom-enabled-themes (quote (tsdh-dark)))
'(erc-hide-list (quote ("JOIN" "KICK" "PART" "QUIT")))
'(inhibit-startup-screen t)
'(org-beamer-frame-level 2)
'(org-hide-leading-stars t)
'(org-odd-levels-only nil)
'(org-startup-truncated nil)
'(outline-regexp "[% ]+" t)
; check the shell interpreter below
'(python-shell-interpreter "/usr/local/bin/ipython3")
;; '(python-shell-prompt-regexp "In \\[[0-9]+\\]: ")
;; '(python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: ")
;; '(python-shell-completion-string-code)
'(python-shell-interpreter-args "--simple-prompt -i")
'(python-shell-completion-setup-code
"from IPython.core.completerlib import module_completion")
'(python-shell-completion-module-string-code
"';'.join(module_completion('''%s'''))\n")
'(python-shell-completion-string-code
"';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
'(python-shell-prompt-detect-failure-warning nil)
'(send-mail-function (quote smtpmail-send-it))
'(smtpmail-smtp-server "mail.kone.ci")
'(smtpmail-smtp-service 25)
'(yas-snippet-dirs (quote ("~/.emacs.d/plugins/yasnippet/snippets")) nil (yasnippet))
; graphviz customization
'(graphviz-dot-auto-indent-on-braces t)
'(graphviz-dot-auto-indent-on-newline t)
'(graphviz-dot-auto-indent-on-semi t)
'(graphviz-dot-delete-completions t)
'(graphviz-dot-toggle-completions nil)
'(graphviz-dot-view-edit-command t)
)
#+END_SRC
** Testing
#+BEGIN_SRC emacs-lisp :tangle no
;; write a function to toggle between light and dark themes
(enable-theme 'tsdh-dark)
;;(enable-theme 'tsdh-light)
(custom-enabled-themes)
(custom-known-themes)
(custom-enabled-theme-p tsdh-dark)
#+END_SRC
#+BEGIN_SRC emacs-lisp
;; make electric-pair-mode work for more brackets
;(setq electric-pair-pairs '( (?\".?\")))
#+END_SRC
* Keyboard shortcuts
:autres-raccourcis-clavier:
mettre de l'ordre ici
# (global-set-key (kbd "C-c @ C-t") 'hide/show-comments-toggle)
# (global-set-key (kbd "C-c @ C-h") 'hs-hide-all)
# (global-set-key (kbd "C-c @ C-s") 'hs-show-all)
# (global-set-key (kbd "C-c @ C-c") 'hs-toggle-hiding)
# (global-set-key (kbd "C-c @ C-c") 'hs-hide-initial-comment-block)
# ; optional key bindings, easier than hs defaults
# (define-key nxml-mode-map (kbd "C-c h") 'hs-toggle-hiding)
:END:
#+BEGIN_SRC emacs-lisp
;;;; raccourcis pour les remplacements
(global-set-key (kbd "C-c r") 'replace-regexp)
(global-set-key (kbd "C-c s") 'replace-string)
#+END_SRC
** web-beautify
#+BEGIN_SRC emacs-lisp
;;;; web-beautify
(eval-after-load 'js2-mode
'(define-key js2-mode-map (kbd "C-c b") 'web-beautify-js))
(eval-after-load 'json-mode
'(define-key json-mode-map (kbd "C-c b") 'web-beautify-js))
(eval-after-load 'sgml-mode
'(define-key html-mode-map (kbd "C-c b") 'web-beautify-html))
(eval-after-load 'css-mode
'(define-key css-mode-map (kbd "C-c b") 'web-beautify-css))
#+END_SRC
#+RESULTS:
** Org-key
#+BEGIN_SRC emacs-lisp
;;;; Org-key
(global-set-key "\M-=" 'org-show-current-heading-tidily)
(global-set-key (kbd "C-c C-S-o") 'org-odt-export-to-odt)
#+END_SRC
** EIN-key
#+BEGIN_SRC emacs-lisp
;;;; pour EIN mode
(global-set-key (kbd "C-c e p") 'ein:jupyter-server-stop)
(global-set-key (kbd "C-c e r") 'ein:jupyter-server-start)
(define-key ein:notebook-mode-map "\C-c\C-d" 'ein:worksheet-delete-cell)
#+END_SRC
** Yas-key
#+BEGIN_SRC emacs-lisp
;;;; Yasnipet
(global-set-key (kbd "C-c & C-l") 'yas-load-directory)
(global-set-key (kbd "C-c & C-a") 'yas-reload-all)
#+END_SRC
** Ispell
#+BEGIN_SRC emacs-lisp
;;;; Ispell
(global-set-key (kbd "C-$") 'ispell-complete-word)
#+END_SRC
** notes.org file
#+BEGIN_SRC emacs-lisp
(defun ff-abstract ()
"format abstract. Need the point at the beggining of the region"
(interactive)
(while (search-forward "
" (region-end) t)
(replace-match " " nil t))
(while (search-forward "- " (region-end) t)
(replace-match "" nil t))
(while (search-forward "." (region-end) t)
(replace-match ". " nil t))
)
(global-set-key (kbd "C-c f") 'ff-abstract)
#+END_SRC
* Fonts
I tried to set font size by hand not sure if it work because other setting done previously
#+BEGIN_SRC emacs-lisp
;;;;;;;;;;;;;;;; Fonts
; (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-12"))
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
#+END_SRC
** Custom-set-faces
#+BEGIN_SRC emacs-lisp
(custom-set-faces
; ; custom-set-faces was added by Custom.
; ; If you edit it by hand, you could mess it up, so be careful.
; ; Your init file should contain only one such instance.
; ; If there is more than one, they won't work right.
'(default ((t (:family "DejaVu Sans" :foundry "PfEd" :slant normal :weight normal :height 128 :width normal))))
'(org-table ((t (:foreground "LightSkyBlue" :family "Ubuntu Mono")))))
#+END_SRC
#+BEGIN_SRC emacs-lisp
;(add-to-list 'default-frame-alist '(font . "Monospace-10"))
;(add-to-list 'default-frame- '(font . "DejaVu Sans Mono-10"))
; '(default ((t (:family "Ubuntu Mono" :foundry "DAMA" :slant normal :weight normal :height 143 :width normal))))
#+END_SRC
################ activate persistant history accross terminals
hid_pat='[[:digit:]]+' #history id
date_pat='[0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+' # a factoriser
history_pat="^ *$hid_pat *($date_pat) *(.*)"
log_persistent_history() {
# Save the last history command to ph_file independently of terminal
if [ ! -f $ph_file ]; then touch $ph_file; fi
# extract parts of the last history
[[ $(history 1) =~ $history_pat ]]
date_time_part="${BASH_REMATCH[1]}"
cmd_part="${BASH_REMATCH[2]}"
# if the commande was used previously, remove the line and create one with an updated timestamp
saving_check_pat="$date_pat *$cmd_part *"
if egrep -q "$saving_check_pat" "$ph_file"; then
sed_check_pat=${saving_check_pat/\//\\\/}
sed -rie "/$sed_check_pat/d" "$ph_file"
fi
echo "$date_time_part $cmd_part" >> $ph_file
}
#### history alias
alias hgrep="history | egrep "
alias phgrep="cat $ph_file | egrep"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment