diff --git a/configs/spacemacs-default/dot-layers.el b/configs/spacemacs-default/dot-layers.el index 76bcffbc4180f7e190881f6605477ca15c703120..9e7d531fdc1d30ae91eee4446e5fe5528b4cca6c 100644 --- a/configs/spacemacs-default/dot-layers.el +++ b/configs/spacemacs-default/dot-layers.el @@ -5,12 +5,12 @@ (append dotspacemacs-configuration-layers '( ;; -------- Languages - ess + ;; ess ;; html ;; latex ;; markdown ;; python - julia + ;; julia ;; javascript ;; sql ;; go @@ -21,10 +21,10 @@ ;; csv ;; -------- Applications - org + ;; org ;; gnus ;; fasd - lsp + ;; lsp ;; -------- Project management ;; (treemacs :variables diff --git a/configs/spacemacs-minimal/init.el b/configs/spacemacs-minimal/init.el index c4c074136dfefc74bcd602c48df0da84187dbab7..0e1857fe588457f4ddfa19a8313b54b501fccf25 100644 --- a/configs/spacemacs-minimal/init.el +++ b/configs/spacemacs-minimal/init.el @@ -38,6 +38,7 @@ This function should only modify configuration layer settings." (smartparens :location local) (dired :location local) (pdfs :location local) + (stats :location local) ) ) @@ -166,9 +167,6 @@ before packages are loaded." ;; -------------------------------------------------- (spacemacs/toggle-centered-point-globally-on) - (ulys/conf/dired) - (ulys/conf/kbd) - ;; -------------------------------------------------- ;; ----- Configuration specific to this version ----- ;; -------------------------------------------------- @@ -176,21 +174,6 @@ before packages are loaded." (dotspacemacs/user-config-specific) ) - ; dired config -(defun ulys/conf/dired () -) - ; 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 diff --git a/configs/spacemacs-test/dot-layers.el b/configs/spacemacs-test/dot-layers.el index ac2916da97eb589db2be8787b50c38e4bd22b7d4..3b663ef075002503287ff3589c8418b17025b219 100644 --- a/configs/spacemacs-test/dot-layers.el +++ b/configs/spacemacs-test/dot-layers.el @@ -5,12 +5,12 @@ (append dotspacemacs-configuration-layers '( ;; -------- Languages - ess + ;; ess ;; html ;; latex ;; markdown ;; python - julia + ;; julia ;; javascript ;; sql ;; go @@ -21,10 +21,10 @@ ;; csv ;; -------- Applications - org + ;; org ;; gnus ;; fasd - lsp + ;; lsp ;; -------- Project management ;; git diff --git a/layers/general/config.el b/layers/general/config.el index b13a9c4517c24dd8ab50ed957b5d7b269314705c..94caadb0270f4e4b31fc0b292b4b28666e7f0637 100644 --- a/layers/general/config.el +++ b/layers/general/config.el @@ -15,173 +15,10 @@ (setq org-list-allow-alphabetical t) (setq org-hide-emphasis-markers t) (require 'org-tempo) -;; (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/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/config/org-babel () - (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//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-tempo () - ;; In org mode : auto complete #+begin #+end - (require 'org-tempo)) -(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")) +(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) diff --git a/layers/general/funcs.el b/layers/general/funcs.el index 1892e33c3589790e7b4f588f756bd344940f0815..7181d5b2a0191fded85b5d29675d8a15aa4b44fd 100644 --- a/layers/general/funcs.el +++ b/layers/general/funcs.el @@ -57,8 +57,6 @@ process." (kill-buffer region-to-process-target) (add-to-list 'kill-buffer-query-functions 'process-kill-buffer-query-function) ) -(defun ulys/conf/toggle-shell () - (setq ulys/toggle-shell-on nil)) (defun ulys/toggle-shell () (interactive) (if ulys/toggle-shell-on @@ -69,3 +67,175 @@ process." (interactive) (setq ulys/toggle-shell-on t) (ulys/open-ansi-term)) + +;; ----- Org +;; interactive +(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/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)) + +;; config +(defun ulys/config/org-tempo () + ;; In org mode : auto complete #+begin #+end + (require 'org-tempo)) +(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")) +(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/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))) diff --git a/layers/stats/config.el b/layers/stats/config.el new file mode 100644 index 0000000000000000000000000000000000000000..76784a2490f04c23d0407532c97275e4c2b4e3fb --- /dev/null +++ b/layers/stats/config.el @@ -0,0 +1 @@ +(setq ess-save-silently t) diff --git a/layers/stats/funcs.el b/layers/stats/funcs.el new file mode 100644 index 0000000000000000000000000000000000000000..a9fa07d4da41131de694015c1ee0beb033416079 --- /dev/null +++ b/layers/stats/funcs.el @@ -0,0 +1,26 @@ +(defun ulys/ess-insert-magrittr-pipe () + "Insert magrittr pipe at i.e. \"%>%\"." + (interactive) + (insert "\n %>% ")) +(defun ulys/ess-insert-right-assign-operator () + "Insert \"->\"." + (interactive) + (insert " -> ")) +(defun ulys/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/ess-backquote-delete-df$ () + (interactive) + (ulys/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) + ) diff --git a/layers/stats/keybindings.el b/layers/stats/keybindings.el new file mode 100644 index 0000000000000000000000000000000000000000..64a644eaa1850db3deb455a573b7713b84a91d8e --- /dev/null +++ b/layers/stats/keybindings.el @@ -0,0 +1,11 @@ +(add-hook 'ess-mode-hook + (lambda () + (define-key ess-mode-map (kbd ";") 'ess-insert-assign) + (define-key ess-mode-map (kbd "C-;") 'ulys/ess-insert-magrittr-pipe) + (define-key ess-mode-map (kbd "C-:") + 'ulys/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/ess-backquote-from-dollar) + (define-key ess-mode-map (kbd "C-~") 'ulys/ess-backquote-delete-df$) + )) diff --git a/layers/stats/layers.el b/layers/stats/layers.el new file mode 100644 index 0000000000000000000000000000000000000000..afed5d5a217474b306b977c94a14a42a03c2006f --- /dev/null +++ b/layers/stats/layers.el @@ -0,0 +1,6 @@ +(configuration-layer/declare-layers + '( + ess + julia + ) +) diff --git a/layers/stats/packages.el b/layers/stats/packages.el new file mode 100644 index 0000000000000000000000000000000000000000..a1add77213e514369fdbc35fca56167ff0cd937c --- /dev/null +++ b/layers/stats/packages.el @@ -0,0 +1,4 @@ +(defconst stats-packages + '( + ) + )