diff --git a/configuration.org b/configuration.org index 20bde9f7d0d7aa30a110bc40ec96090007485b1d..61cc868b633e9d1d8ddbd059b68b044c68a115a9 100644 --- a/configuration.org +++ b/configuration.org @@ -2,6 +2,7 @@ #+author: Michaƫl Hauspie #+email: michael.hauspie@univ-lille.fr #+language: en +#+property: header-args :results none Some of my configuration entries where borrowed from other people, see [[*Acknowledgment][Acknowledgment]] section for a list. @@ -51,17 +52,17 @@ Sets who I am I use [[https://elpa.gnu.org][Elpa]], [[https://melpa.org][Melpa]] and [[http://orgmode.org][Org mode]] packages repository, thus I need to add them to the =package-archives= list - For older emacs version, fix some gnutls algorithm priority +For older emacs version, fix some gnutls algorithm priority - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") - #+END_SRC +#+END_SRC - #+RESULTS: - : NORMAL:-VERS-TLS1.3 +#+RESULTS: +: NORMAL:-VERS-TLS1.3 - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (require 'package) (add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/") t) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) @@ -69,7 +70,7 @@ I use [[https://elpa.gnu.org][Elpa]], [[https://melpa.org][Melpa]] and [[http:// (package-initialize) #+END_SRC - #+RESULTS: +#+RESULTS: Then, to ensure that packages are installed and that I can launch @@ -127,26 +128,26 @@ Add a folder for .el files that are not available as packages I use [[https://github.com/technomancy/better-defaults][better-defaults]] to tweak some annoying Emacs default behaviors. The two most important beeing: - - use =ido= almost everywhere - - put temporary files in a specific folder rather as =~= files everywhere +- use =ido= almost everywhere +- put temporary files in a specific folder rather as =~= files everywhere - there is more to =better-defaults=, be sure to have a look at its list - of changed behaviors. In particular, it switches the menu bar off and - I quite like have it around sometimes, so I re-enable it. + there is more to =better-defaults=, be sure to have a look at its list + of changed behaviors. In particular, it switches the menu bar off and + I quite like have it around sometimes, so I re-enable it. - #+BEGIN_SRC emacs-lisp + #+BEGIN_SRC emacs-lisp (use-package better-defaults) ;; I want menu bar (menu-bar-mode t) - #+END_SRC + #+END_SRC - Ido is not set everywhere by =better-defaults= and I really want it everywhere + Ido is not set everywhere by =better-defaults= and I really want it everywhere - #+begin_src emacs-lisp + #+begin_src emacs-lisp (setq ido-enable-flex-matching t) (setq ido-everywhere t) - #+end_src + #+end_src As I often use Emacs on MacOS, I need the right option (alt) key to @@ -254,6 +255,13 @@ Define a shortcut to re-indent all buffer. This saves the current point, marks w #+RESULTS: : mh/indent-buffer +Set the line width for fill command + +#+begin_src emacs-lisp +(setq-default fill-column 100) +#+end_src + + ** Undo on steroids Manage undo as a tree so that we can undo/redo more. Bound by default on =C-x u= @@ -271,9 +279,8 @@ Manage undo as a tree so that we can undo/redo more. Bound by default on =C-x u= ** Changes to builtin visuals -I always display visual line where the cursor is and I like to have -line numbers at the left of the buffer. I also have Emacs to show me -matching parenthesis. Also do not show the welcome screen. +I always display visual line where the cursor is and I like to have line numbers at the left of the +buffer. I also have Emacs to show me matching parenthesis. Also do not show the welcome screen. #+BEGIN_SRC emacs-lisp ;; Do not show welcome screen @@ -311,11 +318,11 @@ Use Fira Code but do not use ligature everywhere #+begin_src emacs-lisp (use-package fira-code-mode :config - ;(global-fira-code-mode) + ;(global-fira-code-mode) (setq fira-code-mode-enable-hex-literal nil) ) - (add-to-list 'default-frame-alist '(font . "Fira Code-12" )) - (set-face-attribute 'default t :font "Fira Code-12" ) +(add-to-list 'default-frame-alist '(font . "Fira Code-12" )) +(set-face-attribute 'default t :font "Fira Code-12" ) #+end_src #+RESULTS: @@ -367,38 +374,38 @@ and loaded. *** TRAMP configuration for remote editing - Tramp is a mode that allows emacs to edit file remotely (over ssh) or - even as =sudo= (even combining both, effectively editing a file on a - remote machine as root while connecting to the remote machine using - ssh as an unpriviledged user) +Tramp is a mode that allows emacs to edit file remotely (over ssh) or +even as =sudo= (even combining both, effectively editing a file on a +remote machine as root while connecting to the remote machine using +ssh as an unpriviledged user) - To open a file located on a remote machine, simply open the file - =/ssh:user@host:path/to/the/file= +To open a file located on a remote machine, simply open the file +=/ssh:user@host:path/to/the/file= - To =sudo= open a local file : =/sudo::/path/to/the/file=. +To =sudo= open a local file : =/sudo::/path/to/the/file=. - Combining both : =/ssh:user@host|sudo::/path/to/the/file=. +Combining both : =/ssh:user@host|sudo::/path/to/the/file=. - There is no real configuration need for my tramp usage, however, I - would like to display on the mode line on which host I am editing (one - of the many reason is that I find myself editing the same file on - different servers on many occasions). By default, a =@= symbol is - displayed on the mode line when editing remote, but not the server - hostname. It requires mousing hover the =@= which is... impractical at - the very best. +There is no real configuration need for my tramp usage, however, I +would like to display on the mode line on which host I am editing (one +of the many reason is that I find myself editing the same file on +different servers on many occasions). By default, a =@= symbol is +displayed on the mode line when editing remote, but not the server +hostname. It requires mousing hover the =@= which is... impractical at +the very best. - For this, I use the =tramp-theme= package that does what I want. +For this, I use the =tramp-theme= package that does what I want. - #+begin_src emacs-lisp +#+begin_src emacs-lisp (use-package tramp-theme :ensure t :config (load-theme 'tramp t) -) - #+end_src + ) +#+end_src - #+RESULTS: - : t +#+RESULTS: +: t ** Shortcut dynamic help buffer @@ -492,10 +499,11 @@ Add shortcuts to quickly add code blocks using =C-,= Use =latexmk= to export to Latex #+begin_src emacs-lisp :exports code -(setq org-latex-pdf-process (list "latexmk -pdflatex='pdflatex -shell-escape -interaction nonstopmode' -pdf %f")) +(setq org-latex-pdf-process (list "latexmk -pdflatex='pdflatex -shell-escape -interaction nonstopmode' -output-directory=%o -pdf %f")) #+end_src + Use =org-ref= for citation #+begin_src emacs-lisp @@ -513,6 +521,21 @@ And use the same shortcut for =org-reftex-citation= than for =reftex-citation= #+RESULTS: : org-reftex-citation +Define a document class that do not use parts and start with chapters + +#+begin_src emacs-lisp +(add-to-list 'org-latex-classes + '("book-noparts" + "\\documentclass{book}" + ("\\chapter{%s}" . "\\chapter*{%s}") + ("\\section{%s}" . "\\section*{%s}") + ("\\subsection{%s}" . "\\subsection*{%s}") + ("\\subsubsection{%s}" . "\\subsubsection*{%s}") + ("\\paragraph{%s}" . "\\paragraph*{%s}") + ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))) +#+end_src + + ** Visuals Use bullets instead of asterisks @@ -684,19 +707,14 @@ using bootstrap template. #+RESULTS: -So that code highlighting can be done using [[https://www.ctan.org/pkg/minted][minted]] (which uses -[[https://pygments.org/][Pygments]] as an external tool), we need to change latex export commands. +Configure code highlighting using [[https://www.ctan.org/pkg/minted][minted]] (which uses +[[https://pygments.org/][Pygments]] as an external tool) for latex export #+begin_src emacs-lisp ;; Configure ox-latex to export source block using minted ;; Setting minted cache to false as cache seems to fail when changing the output-directory (add-to-list 'org-latex-packages-alist '("cache=false" "minted")) (setq org-latex-listings 'minted) - -(setq org-latex-pdf-process - '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f" - "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f" - "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f")) #+end_src For HTML source code highlight, use =htmlize= @@ -1040,7 +1058,7 @@ For dockerfiles and docker-compose files, install some docker packages (use-package dockerfile-mode) (use-package docker-compose-mode) (use-package docker) -(use-package docker-tramp) +;(use-package docker-tramp) (use-package docker-api) (use-package docker-cli) #+end_src @@ -1142,12 +1160,12 @@ cargo install slint-lsp [[https://magit.vc/][Magit]] is git porcelain inside emacs. - + Bind =C-x g= to pop up the magit status buffer - + configure magit to automatically revert buffers that are opened - if they are modified by a magit action (such as changing branch, - merging...) - + Save buffers that visit a file that belongs to a repository if - needed ++ Bind =C-x g= to pop up the magit status buffer ++ configure magit to automatically revert buffers that are opened + if they are modified by a magit action (such as changing branch, + merging...) ++ Save buffers that visit a file that belongs to a repository if + needed #+begin_src emacs-lisp (use-package magit diff --git a/plugins/json-to-org-table.el b/plugins/json-to-org-table.el new file mode 100644 index 0000000000000000000000000000000000000000..4ec71fe434d1b0774cb30d059b27cc9f335f216f --- /dev/null +++ b/plugins/json-to-org-table.el @@ -0,0 +1,202 @@ +;;; json-to-org-table.el --- Converts json string to linked org table -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2020 Joshua Person +;; +;; Author: Joshua Person <http://github.com/noonker> +;; Maintainer: Joshua Person <ceo@legitimate.company> +;; Created: December 06, 2020 +;; Modified: December 06, 2020 +;; Version: 0.0.1 +;; Keywords: +;; Homepage: https://github.com/noonker/json-to-org-table +;; Package-Requires: ((emacs 27.1)) +;; +;; This file is not part of GNU Emacs. +;; +;;; Commentary: +;; +;; Converts json string to linked org table +;; +;;; Code: +;;; TODO: Better Examples + +(defvar j2t-debug nil) + +(defvar j2t-cs-map [("\r" "") + ("\n" "")] + "Map of characters to replace in json string.") + +(defun j2t-cs (str) + "Clean String. +Replace any string org mode wouldn't like according to the j2t-cs-map +STR: String to be replaced +RETURNS: A string with problematic characters returned" + (seq-reduce + (lambda (s m) (replace-regexp-in-string (car m) (cadr m) s)) + j2t-cs-map (format "%s" str))) + +(defun j2t-lf (key &optional ref i) + "Convert to link Link Format based on available args. +KEY: String or Symbol that becomes the name of the table +REF: If there is a Reference that becomes a subkey of the link +I: Is the Index for links in vectors" + (cond (i (format "[[%s_%s%s]]" key ref (number-to-string i))) + (ref (format "[[%s_%s]]" key ref)) + (t (format "[[%s]]" key)))) + +(defun j2t-hp (key value) + "Hashmap Print prints a hashmap key-value table row. +KEY: Hashmap key column +VALUE: Hashmap value column" + (format "|%s|%s|\n" (j2t-cs key) (j2t-cs value))) + +(defmacro j2t-c+ (&rest str) + "HACK: Concatenates all args and update the value of cur with new STR. +There's probably a better way to do this but this keeps things as clean +as possible in the =tablify= function." + `(setq cur (concat cur (concat ,@str )))) + +(defun j2t-parse-vector-vector (elt) + "The row parser for a vector of vectors. +ELT: Is a vector to be turned into a table row +RETURNS: A table row representing the values of a vector" + (let ((cur "")) + (j2t-c+ "|") + (mapc (lambda (x) (j2t-c+ (j2t-cs (format "%s" x)) "|" )) elt) + (j2t-c+ "\n") + cur + ) + ) + +(defun j2t-parse-hashmap-vector (elt &optional ref i) + "A row parser for a vector element composed of hashmaps. +ELT: A dotted pair cons representing a json hashmap +REF: Reference if this is a linked table +I: Optional Index for multiple linked tables +RETURNS: The table row representing values of a hashmap and a + list of subtables to create if applicable +EXAMPLE: ((a . (b . 2)) (c . d) (e . f)) -> '(\"|[[a]]|d|f|]\" '(a (b .2) 1))" + (let ((cur "") + (keys (mapcar #'car elt)) + (nex '())) + (mapcar (lambda (key) + (let ((value (alist-get key elt))) + (if (consp value) + (progn + (j2t-c+ (j2t-lf key ref i) "|") + (setq nex (append nex '('(key value i))))) + (j2t-c+ (j2t-cs value) "|" ))) + ) keys) + `(,cur ,nex) + )) + + + (defun j2t-parse-hash-element (elt &optional ref) + "A row parser for elements of a hash map. +ELT: A dotted pair cons representing a json hashmap +REF: Reference if this is a linked table +RETURNS: Return an object who's first element is the generated string + and the second element is the key if a new table is required. +EXAMPLE: (a . b) -> '(\"|a|b|\n\" '())" + (let ((key (car elt)) + (val (cdr elt))) + (cond ((not val) `(,(j2t-hp key "") nil)) + ((vectorp val) `(,(j2t-hp key (j2t-lf key ref)) ,key)) + ((consp val) `(,(j2t-hp key (j2t-lf key ref)) ,key)) + (t `(,(j2t-hp key (format "%s" val)) nil)) + ))) + +(defun j2t-tablify (elt &optional ref) + "Function to be called recusrively to build an table. +ELT: a json object +REF: a reference is this is a linked table" + (let ((cur "") + (nex '())) + (if j2t-debug (message (format "Got here! I was called with:\n elt: %s\n ref: %s\n" elt ref))) + (if ref (j2t-c+ (format "#+name: %s\n" ref))) ;; If there's a reference add a name block to establish the linkage + + (cond + ;; ----- Element is a hash-map ----- + ((consp elt) + (progn + (j2t-c+ "|key|value|\n|-\n") ;; Add headers for hashmap table + ;; For each element in the hashmap either add the value or add a link to the table of values + (mapc (lambda (x) (let ((parsed (j2t-parse-hash-element x ref))) + (format "x: %s\nparsed: %s" x parsed) + (j2t-c+ (car parsed)) + (if (cadr parsed) (setq nex (append (cdr parsed) nex))))) elt) + (j2t-c+ "\n") + ;; Recursively call this function to create any subtables + (mapc (lambda (x) (progn (if j2t-debug (message (format "\nThe symbol I'm going to look up is: %s\n it's type is: %s\n and the value is: %s" x (type-of x) (alist-get x elt)))) + (if ref + (j2t-c+ (j2t-tablify (alist-get x elt) (format "%s_%s" x ref))) + (j2t-c+ (j2t-tablify (alist-get x elt) (format "%s" x)))))) nex) + )) + + ;; ----- Element is a vector and is a vector of hash-maps ----- + ((and (vectorp elt) + (consp (aref elt 0))) + (let ((keys (mapc #'car (aref elt 0))) + ) + (j2t-c+ (format "|%s|\n" (string-join (mapcar (lambda (x) (format "%s" (car x))) keys) "|"))) + (j2t-c+ "|-\n") + (seq-map-indexed + (lambda (elt idx) + (let ((parsed (j2t-parse-hashmap-vector elt ref idx))) + (j2t-c+ "|") + (j2t-c+ (car parsed)) + (j2t-c+ "\n") + (if (cadr parsed) (setq nex (append (cdr parsed) nex)))) + ) elt) + ) + + ;; Recursively call this function to create any subtables + (mapc (lambda (x) (let ((key (nth 0 x)) + (value (nth 1 x)) + (i (nth 2 x))) + (j2t-c+ (j2t-tablify value (format "%s_%s%s" key ref (format "%s" i)) )))) nex) + ) + + ;; ----- Element is a vector of vectors ----- + ((and (vectorp elt) + (vectorp (aref elt 0))) + (let ((a nil)) + (mapc (lambda (x) (j2t-c+ (j2t-parse-vector-vector x))) elt) + (j2t-c+ "\n") + )) + + ;; ----- Element is an empty vector ----- + ((and (vectorp elt) + (= (length elt) 0)) + (j2t-c+ "| |\n") + ) + + ;; ----- Element is a vector of strings ----- + ((vectorp elt) + (j2t-c+ (format "|%s|\n|-\n" ref)) + (mapc (lambda (x) (j2t-c+ "|" (j2t-cs x) "|" "\n")) elt) + ) + ) + cur + ) + ) + +(defun json-to-org-table-parse-json-string (str) + "Read a json string, parse it, and return a tablified string. +STR: json string" + (j2t-tablify (json-read-from-string str))) + +(defun json-to-org-table-parse-json (js) + "Read an Emacs json object, parse it, and return a tablified string. +The json should be in the format: + - lists -> vectors + - hashmaps -> alist cons + - null -> \"\" + - bool -> :json-true / :json-false +JS: json object" + (j2t-tablify js)) + +(provide 'json-to-org-table) + +;;; json-to-org-table.el ends here +