Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing indentation in emacs ess [closed]

Tags:

I would like to know how can I change indentation in emacs ess. I generally like default one (ess-set-style 'C++ 'quiet) But sometimes it formats really weirdly. For example this is what I would like to have, and this will be default formatting if it is not part of the function:

  ggplot(data = overtime.by.month,
         aes(x="",
             y=Percent,
             fill = Overtime)) +
  geom_bar(width = 1) +
  xlab('') +
  ylab(sub.txt) +
  labs(title = title.txt) +
  facet_wrap(~Year.Month) +
  geom_text(aes(y = txt.pos, label = Per.txt)) +
  coord_polar(theta = "y") +
  scale_fill_manual(values = c('green', 'red')) +
  theme(axis.ticks = element_blank(),
        axis.text.y = element_blank(),
        axis.text.x = element_blank())

This is what I get with current indentation style, if I put it inside of the function.

a <- function(){

    a <- ggplot(data = overtime.by.month,
                aes(x="",
                    y=Percent,
                    fill = Overtime)) +
                        geom_bar(width = 1) +
                            xlab('') +
                                ylab(sub.txt) +
                                    labs(title = title.txt) +
                                        facet_wrap(~Year.Month) +
                                            geom_text(aes(y = txt.pos, label = Per.txt)) +
                                                coord_polar(theta = "y") +
                                                    scale_fill_manual(values = c('green', 'red')) +
                                                        theme(axis.ticks = element_blank(),
                                                              axis.text.y = element_blank(),
                                                              axis.text.x = element_blank())
}

UPDATE: I followed both VitoshKa's and Dirk's suggestions, after reinstallation, and updating .emacs problem went away. Thank you guys

UPDATE2: Problem is back. I think now it will be reproducible for all. I tried to on two different machines. It happens when you put code inside of the function. I updated post to reflect changes.

like image 889
ilya Avatar asked Oct 09 '12 18:10

ilya


1 Answers

I get

ggplot(data = overtime.by.month,
       aes(x="",
           y=Percent,
           fill = Overtime)) +
    geom_bar(width = 1) +
    xlab('') +
    ylab(sub.txt) +
    labs(title = title.txt) +
    facet_wrap(~Year.Month) +
    geom_text(aes(y = txt.pos, label = Per.txt)) +
    coord_polar(theta = "y") +
    scale_fill_manual(values = c('green', 'red')) +
    theme(axis.ticks = element_blank(),
          axis.text.y = element_blank(),
          axis.text.x = element_blank())

and I use defaults straight out of the R manuals.

;; R-internals manual
;;; ESS
(add-hook 'ess-mode-hook
      (lambda ()
        (ess-set-style 'C++ 'quiet)
        ;; Because
        ;;                                 DEF GNU BSD K&R C++
        ;; ess-indent-level                  2   2   8   5   4
        ;; ess-continued-statement-offset    2   2   8   5   4
        ;; ess-brace-offset                  0   0  -8  -5  -4
        ;; ess-arg-function-offset           2   4   0   0   0
        ;; ess-expression-offset             4   2   8   5   4
        ;; ess-else-offset                   0   0   0   0   0
        ;; ess-close-brace-offset            0   0   0   0   0
        (add-hook 'local-write-file-hooks
              (lambda ()
            (ess-nuke-trailing-whitespace)))))
;;(setq ess-nuke-trailing-whitespace-p 'ask)
;; or even
(setq ess-nuke-trailing-whitespace-p t)
;; Perl
(add-hook 'perl-mode-hook
      (lambda () (setq perl-indent-level 4)))

You could modify those values in the comment.

like image 172
Dirk Eddelbuettel Avatar answered Sep 27 '22 19:09

Dirk Eddelbuettel