Commit 6f6ccb19 authored by Pierre Balaye's avatar Pierre Balaye

Layer stats created: ess + julia with kbd config

parent 598b6ae1
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......@@ -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)))
(setq ess-save-silently t)
(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)
)
(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$)
))
(configuration-layer/declare-layers
'(
ess
julia
)
)
(defconst stats-packages
'(
)
)
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