.dir-locals.el 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ((java-mode
  2. .
  3. ((eval
  4. .
  5. (progn
  6. (defun my/point-in-defun-declaration-p ()
  7. (let ((bod (save-excursion (c-beginning-of-defun)
  8. (point))))
  9. (<= bod
  10. (point)
  11. (save-excursion (goto-char bod)
  12. (re-search-forward "{")
  13. (point)))))
  14. (defun my/is-string-concatenation-p ()
  15. "Returns true if the previous line is a string concatenation"
  16. (save-excursion
  17. (let ((start (point)))
  18. (forward-line -1)
  19. (if (re-search-forward " \\\+$" start t) t nil))))
  20. (defun my/inside-java-lambda-p ()
  21. "Returns true if point is the first statement inside of a lambda"
  22. (save-excursion
  23. (c-beginning-of-statement-1)
  24. (let ((start (point)))
  25. (forward-line -1)
  26. (if (search-forward " -> {" start t) t nil))))
  27. (defun my/trailing-paren-p ()
  28. "Returns true if point is a training paren and semicolon"
  29. (save-excursion
  30. (end-of-line)
  31. (let ((endpoint (point)))
  32. (beginning-of-line)
  33. (if (re-search-forward "[ ]*);$" endpoint t) t nil))))
  34. (defun my/prev-line-call-with-no-args-p ()
  35. "Return true if the previous line is a function call with no arguments"
  36. (save-excursion
  37. (let ((start (point)))
  38. (forward-line -1)
  39. (if (re-search-forward ".($" start t) t nil))))
  40. (defun my/arglist-cont-nonempty-indentation (arg)
  41. (if (my/inside-java-lambda-p)
  42. '+
  43. (if (my/is-string-concatenation-p)
  44. 16
  45. (unless (my/point-in-defun-declaration-p) '++))))
  46. (defun my/statement-block-intro (arg)
  47. (if (and (c-at-statement-start-p) (my/inside-java-lambda-p)) 0 '+))
  48. (defun my/block-close (arg)
  49. (if (my/inside-java-lambda-p) '- 0))
  50. (defun my/arglist-close (arg) (if (my/trailing-paren-p) 0 '--))
  51. (defun my/arglist-intro (arg)
  52. (if (my/prev-line-call-with-no-args-p) '++ 0))
  53. (c-set-offset 'inline-open 0)
  54. (c-set-offset 'topmost-intro-cont '+)
  55. (c-set-offset 'statement-block-intro 'my/statement-block-intro)
  56. (c-set-offset 'block-close 'my/block-close)
  57. (c-set-offset 'knr-argdecl-intro '+)
  58. (c-set-offset 'substatement-open '+)
  59. (c-set-offset 'substatement-label '+)
  60. (c-set-offset 'case-label '+)
  61. (c-set-offset 'label '+)
  62. (c-set-offset 'statement-case-open '+)
  63. (c-set-offset 'statement-cont '++)
  64. (c-set-offset 'arglist-intro 'my/arglist-intro)
  65. (c-set-offset 'arglist-cont-nonempty '(my/arglist-cont-nonempty-indentation c-lineup-arglist))
  66. (c-set-offset 'arglist-close 'my/arglist-close)
  67. (c-set-offset 'inexpr-class 0)
  68. (c-set-offset 'access-label 0)
  69. (c-set-offset 'inher-intro '++)
  70. (c-set-offset 'inher-cont '++)
  71. (c-set-offset 'brace-list-intro '+)
  72. (c-set-offset 'func-decl-cont '++)
  73. ))
  74. (c-basic-offset . 4)
  75. (c-comment-only-line-offset . (0 . 0))
  76. (fill-column . 140)
  77. (fci-rule-column . 140)
  78. (compile-command . "gradle compileTestJava"))))