diff --git a/01-create-dirs.sh b/01-create-dirs.sh index 81ef79ae293d33e7518589927fb0548e04ea4abb..a89280d31229a66744babf343d9a568e6014be70 100755 --- a/01-create-dirs.sh +++ b/01-create-dirs.sh @@ -5,4 +5,5 @@ mefs_indent_message "Directory tree creation..." mkdir -p $mefs_EMACSDIR/sources mkdir -p $mefs_EMACSDIR/flavors/ ln -sf $mefs_THISREPODIR/configs $mefs_EMACSDIR/ +ln -sf $mefs_THISREPODIR/layers $mefs_EMACSDIR/ diff --git a/configs/spacemacs-default/dot-layers.el b/configs/spacemacs-default/dot-layers.el index 4b0422e821e0885a9176f98b3ca4f9e1bad00420..76bcffbc4180f7e190881f6605477ca15c703120 100644 --- a/configs/spacemacs-default/dot-layers.el +++ b/configs/spacemacs-default/dot-layers.el @@ -21,7 +21,7 @@ ;; csv ;; -------- Applications - ;; org + org ;; gnus ;; fasd lsp diff --git a/configs/spacemacs-default/dot-user-config.el b/configs/spacemacs-default/dot-user-config.el index 85c9209ff0c363a6d37586c42943074ce32861ca..001d0fcd06bfa91b79abd55bf61390ded4ed7724 100644 --- a/configs/spacemacs-default/dot-user-config.el +++ b/configs/spacemacs-default/dot-user-config.el @@ -1,19 +1,231 @@ (defun dotspacemacs/user-config-specific () - (defun ulys/config/org/babel () - - ;; FIXME julia bug - hack I have opened issue #13597 - (setq inferior-julia-program-name "julia") - - (custom-set-variables - '(org-babel-load-languages (quote ((emacs-lisp . t) - (R . t) - (latex . t) - (shell . t) - (ditaa . t) - (julia . t) - (python . t) - (sql . t) - ))) - '(org-confirm-babel-evaluate nil))) + (ulys/config/org) + (ulys/config/ess) + ) + +; ESS config +(defun ulys/config/ess () + (ulys/conf/ess-devtools-save-silentely) + (add-hook 'ess-mode-hook + (lambda () + (define-key ess-mode-map (kbd ";") 'ess-insert-assign) + (define-key ess-mode-map (kbd "C-;") 'ulys/conf/ess-insert-magrittr-pipe) + (define-key ess-mode-map (kbd "C-:") + 'ulys/conf/ess-insert-right-assign-operator) + (define-key ess-mode-map (kbd "C-x C-j") + 'ess-eval-line-invisibly-and-step) + (define-key ess-mode-map (kbd "C-`") 'ulys/conf/ess-backquote-from-dollar) + (define-key ess-mode-map (kbd "C-~") 'ulys/conf/ess-backquote-delete-df$) + ))) +(defun ulys/conf/ess-insert-magrittr-pipe () + "Insert magrittr pipe at i.e. \"%>%\"." + (interactive) + (insert "\n %>% ")) +(defun ulys/conf/ess-insert-right-assign-operator () + "Insert \"->\"." + (interactive) + (insert " -> ")) +(defun ulys/conf/ess-devtools-save-silentely () + (setq ess-save-silently t)) +(defun ulys/conf/ess-backquote-from-dollar () + "Surround with backquotes form last $ till point." + (interactive) + (insert "`") + (setq initial-position (point)) + (evil-find-char-to-backward 1 (string-to-char "$")) + (insert "`") + (goto-char (+ 1 initial-position))) +(defun ulys/conf/ess-backquote-delete-df$ () + (interactive) + (ulys/conf/ess-backquote-from-dollar) + (evil-find-char-to-backward 1 (string-to-char "$")) + (setq dollar-position (point)) + (evil-backward-WORD-begin) + (evil-sp-delete (point) dollar-position) + (evil-find-char 1 (string-to-char "`")) + (evil-forward-char) + ) + +;; Org config +(defun ulys/config/org () + (ulys/config/org/misc) (ulys/config/org/babel) + (ulys/config/org-calendar) +;; (ulys/config/org-minted) +;; (ulys/config/org-odt-export-latexml) +;; (ulys/config/org-capture) +;; (ulys/config/org-file-apps) + ) +(defun ulys/config/org/misc () + (setq org-list-allow-alphabetical t) + (setq org-hide-emphasis-markers t) + ;; <sTAB => src block + (require 'org-tempo) ) +(defun ulys/config/org/babel () + + (setq org-src-window-setup 'current-window) + + ;; FIXME julia bug - hack - have opened issue #13597 + (setq inferior-julia-program-name "julia") + + (custom-set-variables + '(org-babel-load-languages (quote ((emacs-lisp . t) + (R . t) + (latex . t) + (shell . t) + (ditaa . t) + (julia . t) + (python . t) + (sql . t) + ))) + '(org-confirm-babel-evaluate nil))) +(defun ulys/org-insert-csv-as-table (filename) + "Insert a csv file into the current buffer at point, and convert it to an org table." + (interactive (list (ido-read-file-name "csv file: "))) + (let* ((start (point)) + (end (+ start (nth 1 (insert-file-contents filename))))) + (org-table-convert-region start end))) +(defun ulys/config/org-capture () + (setq org-default-notes-file "~/Nextcloud/org/tasks.org" ) + (setq org-capture-templates + '(("t" "Thesis-related Task" entry + (file "~/Nextcloud/org/thesis.org") + "** TODO %?" :empty-lines 1) + ("u" "Teaching-related Task" entry + (file "~/Nextcloud/org/teaching.org") + "** TODO %?" :empty-lines 1) + ("h" "Hospital-related Task" entry + (file "~/Nextcloud/org/hospital.org") + "** TODO %?" :empty-lines 1)))) +(defun ulys/config/org-file-apps () + (defun ulys/org-pdf-app (file-path link-without-schema) + "Open pdf file using pdf-tools and go to the specified page." + (let* ((page (if (not (string-match "\\.pdf::\\([0-9]+\\)\\'" + link-without-schema)) + 1 + (string-to-number (match-string 1 link-without-schema))))) + (find-file-other-window file-path) + (pdf-view-goto-page page))) + (setq org-file-apps + '((auto-mode . emacs) + ("\\.x?html?\\'" . "firefox %s") + ("\\.pdf\\(::[0-9]+\\)?\\'" . whatacold/org-pdf-app) + ("\\.gif\\'" . "eog \"%s\"") + ("\\.mp4\\'" . "vlc \"%s\"") + ("\\.mkv" . "vlc \"%s\"")))) +(defun ulys/config/org-calendar () + (setq calendar-week-start-day 1)) +(defun ulys/org//capture-helper-capture-with-yank-method (method arg) + + ;; helper 1/2 + (defun wrap-into-results-example (capture) + (concat + "#+RESULTS:\n" + "#+ATTR_LATEX: :options frame=lines\n" + "#+BEGIN_SRC R :eval no :tangle no\n" + capture + "\n#+END_SRC\n")) + + ;; helper 2/2 + (defun choose-process (arg) + (if (or arg ;; user asks for selection + (not (boundp 'R-process-target)) ;; target not set + ;; or target is not set to an active process: + (not (process-live-p (get-buffer-process + R-process-target)))) + (setq R-process-target + (completing-read + "Choose R process: " + (seq-map (lambda (el) (buffer-name (process-buffer el))) + (process-list)))))) + + ;; main + (choose-process arg) + (insert (wrap-into-results-example + (funcall method R-process-target)))) +(defun ulys/org/tibble-capture (arg) + "Let the user choose a R process, then kill last tibble output +in the process and insert it in current buffer in a org +#+RESULTS: format." + (interactive "P") + + ;; helper 1/3 + (defun extract-nrows-from-tibble-first-line (line) + "Extract the number N in the pattern: # A tibble N x M" + (let* (( line-without-commas (replace-regexp-in-string "," "" line)) + ( x-position (string-match " x" line-without-commas)) + ( nrow-start-at (length "# A tibble "))) + (string-to-number + (substring line-without-commas nrow-start-at x-position)))) + + + ;; helper 3/3 + (defun yank-last-tibble-from-buffer (buffer) + (interactive) + + (save-current-buffer + (set-buffer buffer) + (search-backward "tibble") + (beginning-of-line) + (let* ((tibble-beg (point)) + (nrow (extract-nrows-from-tibble-first-line (thing-at-point 'line t))) + (tibble-end (progn + (message "nrow: %d" nrow) + (re-search-forward (concat "^" (number-to-string (min 10 nrow)))) + (while (search-forward "#" nil t)) ;; t means no error + (end-of-line) + (point)))) + (buffer-substring tibble-beg tibble-end)))) + + ;; main + (ulys/org//capture-helper-capture-with-yank-method 'yank-last-tibble-from-buffer arg)) +(defun ulys/org/glimpse-capture (arg) + "Let the user choose a R process, then kill last glimpse output +in the process and insert it in current buffer in a org +#+RESULTS: format." + (interactive "P") + + ;; helper 1 + (defun extract-nb-vars-from-glimpse-second-line (line) + "Extract the number N in the pattern: Variables: N" + (let (( nb-vars-start-at (length "Varialbes: ")) + ( nb-vars-end-at (length line))) + (string-to-number + (substring line nb-vars-start-at nb-vars-end-at)))) + + ;; helper 2 + (defun suppress_$_in_front_of_lines (lines) + (replace-regexp-in-string "^\$ " "" lines)) + + ;; helper 3 + (defun yank-last-glimpse-from-buffer (buffer) + (interactive) + + (save-current-buffer + (set-buffer buffer) + (search-backward "Observations: ") + (beginning-of-line) + (let* ((glimpse-beg (point)) + (nrow (progn + (forward-line) + (extract-nb-vars-from-glimpse-second-line + (thing-at-point 'line t)))) + (glimpse-end (progn + (forward-line nrow) + (end-of-line) + (point)))) + (suppress_$_in_front_of_lines + (buffer-substring glimpse-beg glimpse-end) )))) + + ;; main + (ulys/org//capture-helper-capture-with-yank-method 'yank-last-glimpse-from-buffer arg)) +(defun ulys/config/org-minted () + (setq org-latex-listings 'minted + org-latex-packages-alist '(("" "minted")) + 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"))) +(defun ulys/config/org-odt-export-latexml () + (setq org-latex-to-mathml-convert-command"latexmlmath \"%i\" --presentationmathml=%o")) diff --git a/configs/spacemacs-minimal/init.el b/configs/spacemacs-minimal/init.el index c8b80fa3060047163422d16a9d80ab5ad617fbee..53a0ed821a209470f5a08084af3e4c0bb03e49f2 100644 --- a/configs/spacemacs-minimal/init.el +++ b/configs/spacemacs-minimal/init.el @@ -41,6 +41,7 @@ This function should only modify configuration layer settings." ;; List of additional paths where to look for configuration layers. ;; Paths must have a trailing slash (i.e. `~/.mycontribs/') dotspacemacs-configuration-layer-path '() + ;; List of additional packages that will be installed without being ;; wrapped in a layer. If you need some configuration for these ;; packages, then consider creating a layer. You can also put the @@ -48,7 +49,8 @@ This function should only modify configuration layer settings." ;; To use a local version of a package, use the `:location' property: ;; '(your-package :location "~/path/to/your-package/") ;; Also include the dependencies as they will not be resolved automatically. - dotspacemacs-additional-packages '() + dotspacemacs-additional-packages '( + ) ;; A list of packages that cannot be updated. dotspacemacs-frozen-packages '() @@ -75,6 +77,8 @@ This function should only modify configuration layer settings." helm-no-header t) emacs-lisp git + org + smartparens ) ) @@ -274,11 +278,11 @@ It should only modify the values of Spacemacs settings." ;; If non-nil then the last auto saved layouts are resumed automatically upon ;; start. (default nil) - dotspacemacs-auto-resume-layouts nil + dotspacemacs-auto-resume-layouts t ;; If non-nil, auto-generate layout name when creating new layouts. Only has ;; effect when using the "jump to layout by number" commands. (default nil) - dotspacemacs-auto-generate-layout-names nil + dotspacemacs-auto-generate-layout-names t ;; Size (in MB) above which spacemacs will prompt to open the large file ;; literally to avoid performance issues. Opening a file literally means that @@ -505,6 +509,8 @@ If you are unsure, try setting them in `dotspacemacs/user-config' first." ;; -------------------------------------------------- ;; ------ Configuration common to all versions ------ ;; -------------------------------------------------- + (message (concat user-emacs-directory "../../layers/")) + ;; (setq-default dotspacemacs-configuration-layer-path '(concat user-emacs-directory "../../layers/")) ;; -------------------------------------------------- @@ -541,8 +547,10 @@ before packages are loaded." ;; -------------------------------------------------- ;; ------ Configuration common to all versions ------ ;; -------------------------------------------------- - (setq undo-tree-auto-save-history t) - (setq hybrid-style-enable-hjkl-bindings t) + + (ulys/conf/general) + (ulys/conf/dired) + (ulys/conf/kbd) ;; -------------------------------------------------- ;; ----- Configuration specific to this version ----- @@ -551,5 +559,54 @@ before packages are loaded." (dotspacemacs/user-config-specific) ) + ; general config +(defun ulys/conf/general () + (setq undo-tree-auto-save-history t) + (setq vc-follow-symlinks t) ;; To edit .spacemacs without to be prompted each time + (setq hybrid-style-enable-hjkl-bindings t) + (spacemacs/toggle-centered-point-globally-on) + + ;; add time in powerline + (display-time-mode 1) + + ;; New frame will open fullscreen + (add-to-list 'default-frame-alist '(fullscreen . fullboth)) + ) + ; dired config +(defun ulys/conf/dired () + + ;; helpers + (defun ulys/dired-open-current-dir () + (interactive) + (spacemacs/dired ".")) + (defun ulys/conf/dired/kbd/C-hjkl () + (evil-define-key '(normal) dired-mode-map (kbd "C-h") 'dired-up-directory) + (evil-define-key '(normal) dired-mode-map (kbd "C-j") 'evil-next-line) + (evil-define-key '(normal) dired-mode-map (kbd "C-k") 'evil-previous-line) + (evil-define-key '(normal) dired-mode-map (kbd "C-l") 'dired-find-alternate-file)) + + ;; Auto-refresh dired on file change + (add-hook 'dired-mode-hook 'auto-revert-mode) + + (spacemacs/set-leader-keys "ad" 'ulys/dired-open-current-dir) + + ;; (hide .~undo-tree~ files) + (setq dired-omit-verbose nil) + (add-hook 'dired-mode-hook (lambda () (dired-omit-mode))) + (ulys/conf/dired/kbd/C-hjkl)) + ; kbd config +(defun ulys/conf/kbd () + + ;; --- others + ;; C-h to delete buffer and C-S-h for help + (global-set-key (kbd "C-h") 'spacemacs/kill-this-buffer) + + ;; Simulates vim increment and decrement number + (define-key evil-normal-state-map (kbd "C-a C-a") 'evil-numbers/inc-at-pt) + (define-key evil-normal-state-map (kbd "C-x C-x") 'evil-numbers/dec-at-pt) + + ) + + ;; Do not write anything past this comment. This is where Emacs will ;; auto-generate custom variable definitions. diff --git a/configs/spacemacs-test/dot-layers.el b/configs/spacemacs-test/dot-layers.el index 586e4f35762160d6ee7bac30e0a6878628556d65..ac2916da97eb589db2be8787b50c38e4bd22b7d4 100644 --- a/configs/spacemacs-test/dot-layers.el +++ b/configs/spacemacs-test/dot-layers.el @@ -21,7 +21,7 @@ ;; csv ;; -------- Applications - ;; org + org ;; gnus ;; fasd lsp @@ -50,5 +50,11 @@ ;; ------- ;; theming )) - ) + +dotspacemacs-additional-packages +(append dotspacemacs-additional-packages + '( + ) + ) + ) ) diff --git a/configs/spacemacs-test/dot-user-config.el b/configs/spacemacs-test/dot-user-config.el index 85c9209ff0c363a6d37586c42943074ce32861ca..18b85edbadabb8c56e43b25e29ff4dfc90405ae5 100644 --- a/configs/spacemacs-test/dot-user-config.el +++ b/configs/spacemacs-test/dot-user-config.el @@ -1,8 +1,9 @@ (defun dotspacemacs/user-config-specific () (defun ulys/config/org/babel () - ;; FIXME julia bug - hack I have opened issue #13597 - (setq inferior-julia-program-name "julia") + + ;; FIXME julia bug - hack I have opened issue #13597 + (setq inferior-julia-program-name "julia") (custom-set-variables '(org-babel-load-languages (quote ((emacs-lisp . t) @@ -15,5 +16,9 @@ (sql . t) ))) '(org-confirm-babel-evaluate nil))) + + (ulys/config/org/babel) + + (require 'org-tempo) )