Advertisement
Guest User

ESS indentation

a guest
Nov 3rd, 2014
205
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # I've been unhappy with ESS indention for some time, and finally got
  2. # around to trying to adjust it to my taste. It didn't go well, and so
  3. # I'm turning to the collective wisdom of this list for help.
  4. #  
  5. # I don't think what I want is so exotic; basically I like how Rstudio
  6. # indents things, which mostly means lining up things up by reference to
  7. # the calling function. Here are some examples (these examples also
  8. # available at __________ in case your email client doesn't like to use
  9. # a fixed-width font):
  10.  
  11. #Rstudio:
  12. mean(rnorm(100,
  13.            mean = runif(1,
  14.                         1,
  15.                         10)),
  16.      na.rm=TRUE
  17. )
  18.  
  19. # ESS
  20. mean(rnorm(100,
  21.            mean = runif(1,
  22.                1,
  23.                10)),
  24.      na.rm=TRUE
  25.      )
  26.  
  27. # The Rstudio version makes it easy to see which lines are arguments to
  28. # which functions, and I'd like to set ESS to use a similar indentation
  29. # style. I've fiddled with all the ess.*offset variables I can find, but
  30. # I can't seem to find a satisfactory setting.
  31. #  
  32. # The biggest annoyance is the indentation of continuation lines. There
  33. # have been several posts about this including
  34. # http://emacs.1067599.n5.nabble.com/indentation-of-ggplot-code-and-ess-13-09-02-td322315.html
  35. # which suggests the following setting:
  36.  
  37. # (add-to-list 'ess-style-alist
  38. #              '(my-style
  39. #                (ess-indent-level . 4)
  40. #                (ess-first-continued-statement-offset . 2)
  41. #                (ess-continued-statement-offset . 0)
  42. #                (ess-brace-offset . -4)
  43. #                (ess-expression-offset . 4)
  44. #                (ess-else-offset . 0)
  45. #                (ess-close-brace-offset . 0)
  46. #                (ess-brace-imaginary-offset . 0)
  47. #                (ess-continued-brace-offset . 0)
  48. #                (ess-arg-function-offset . 4)
  49. #                (ess-arg-function-offset-new-line . '(4))
  50. #                ))
  51.  
  52.  
  53. #This does improve simple examples such as turning this:
  54.  
  55. 1 +
  56.     2 +
  57.         3 +
  58.             4
  59.  
  60. into
  61.  
  62. 1 +
  63.   2 +
  64.   3 +
  65.   4
  66.  
  67. # though I would really like
  68.  
  69. 1 +
  70. 2 +
  71. 3 +
  72. 4
  73.  
  74. # But it still leave more complicated things like
  75.  
  76. mean(rnorm(100)) +
  77.   2 +
  78.   mean(rnorm(100,
  79.              mean = runif(1, 1, 10)), na.rm=TRUE) +
  80.                2 +
  81.                2
  82.  
  83. # I really don't understand why it makes sense to indent the "2's"
  84. # differently depending on whether they come before or after the second
  85. # "mean(rnorm(...". Compare this to the Rstudio indentation:
  86.  
  87. mean(rnorm(100)) +
  88.   2 +
  89.   mean(rnorm(100,
  90.              mean = runif(1, 1, 10)), na.rm=TRUE) +
  91.   2 +
  92.   2
  93.  
  94. # Right. So I hate to be that guy, but seriously, how can I make ESS
  95. # indentation behave more like Rstudio?
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement