R witnessed the smart introduction of the piping operator
then operator in code which I use quite frequently nowadays. I wonder if this has already been implemented in the newest version of ESS. If not, it shouldn't be a problem to come up with
elisp code to write a function for it. I need to implement this so that it will print that operator
%>% and then jumps to a new indented line.
library(ggplot2) library(dplyr) diamonds %>% filter(cut=="Ideal") %>% ggplot(aes(price)) + geom_histogram() + facet_wrap (~ color)
My elisp trial - in
(defun then_R_operator () "%>% operator or 'then' pipe operator" (interactive) (insert " %>%") ; note the space before the first % (reindent-then-newline-and-indent)) (global-set-key (kbd "C-%") 'then_R_operator)
It works, but I want to check if there is something wrong with it or are there any suggestions to improve it (being a newbie in elisp). How to restrict this only to
I realized that font-locking of
%>% can be done by enabling
ess-fl-keyword:operatorsfrom the ESS menu.
(just-one-space 1)before the pipe. You want use the
ess-mode-map(and propably the
inferior-ess-mode-map) to set the key with
(define-key ess-mode-map (kbd "C-%") 'then_R_operator).
ess-modeactivates itself when editing, e.g.,
inferior-ess-modeactivates when running an interactive
Rprocess inside Emacs (i.e. through the
Rcommand or with
C-c C-zwhich calls
inferior...this will let me use it in the interactive R console, which is inside Emacs? if yes then I think it would be better to define keys for both