From 6f6ccb19f5182adb6cbdab4e037226785574418d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Balay=C3=A9?= <pierre.balaye@univ-lille.fr> Date: Thu, 21 May 2020 00:23:55 +0200 Subject: [PATCH] Layer stats created: ess + julia with kbd config --- configs/spacemacs-default/dot-layers.el | 8 +- configs/spacemacs-minimal/init.el | 19 +-- configs/spacemacs-test/dot-layers.el | 8 +- layers/general/config.el | 175 +----------------------- layers/general/funcs.el | 174 ++++++++++++++++++++++- layers/stats/config.el | 1 + layers/stats/funcs.el | 26 ++++ layers/stats/keybindings.el | 11 ++ layers/stats/layers.el | 6 + layers/stats/packages.el | 4 + 10 files changed, 235 insertions(+), 197 deletions(-) create mode 100644 layers/stats/config.el create mode 100644 layers/stats/funcs.el create mode 100644 layers/stats/keybindings.el create mode 100644 layers/stats/layers.el create mode 100644 layers/stats/packages.el diff --git a/configs/spacemacs-default/dot-layers.el b/configs/spacemacs-default/dot-layers.el index 76bcffb..9e7d531 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 c4c0741..0e1857f 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 ac2916d..3b663ef 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 b13a9c4..94caadb 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 1892e33..7181d5b 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 0000000..76784a2 --- /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 0000000..a9fa07d --- /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 0000000..64a644e --- /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 0000000..afed5d5 --- /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 0000000..a1add77 --- /dev/null +++ b/layers/stats/packages.el @@ -0,0 +1,4 @@ +(defconst stats-packages + '( + ) + ) -- GitLab