1

For my current config, I'm tangling an org-mode buffer into my init.el, and I have a few sections where I'd like to insert rich text between segments of Emacs lisp code, like the following:

...

#+BEGIN_SRC elisp
(use-package exwm
  :config
  (exwm-enable)
#+END_SRC

I find that four workspaces is enough to start out with, and I like being able
to use my X windows across workspaces.

#+BEGIN_SRC elisp
  :init
  (setq exwm-workspace-number 4
        exwm-workspace-show-all-buffers t
        exwm-layout-show-all-buffers t)
#+END_SRC

...

The issue is, if I C-c ' to edit the second SRC block, it reindents to the beginning of the line. Smartparens is also unhappy about any unmatched closing parentheses I have in subsequent blocks.

Is there anything in org-mode that would support something like this? Perhaps some marker I can tag each block with as a hint that they should all be pulled into the same Org Src buffer when I C-c ' on one of them?

4
  • 1
    I would not split a single expression between multiple src blocks: it's like having y = x + in one block and x*4 in another: they cannot be evaluated independently and it is very confusing. Why not add comments to the src block? They will appear in init.el but so what? You can never have enough documentation. – NickD Apr 6 '20 at 0:24
  • 1
    Note also that you can use <<noweb>> syntax. One (use-package block with multiple <<subsections>>, and you can define the subsections elsewhere. Would that help? – mankoff Apr 21 '20 at 20:25
  • Thank you for the suggestion, @mankoff. This is the closest to what I was looking for, but it's unfortunately still a bit too much overhead for my tastes. It seems what I'm trying to do doesn't make much sense in Org, so I've deferred to a plain init.el with comments. – Jakob May 14 '20 at 23:45
  • What about multiple use-package statements as I suggest in the answer below? What about that doesn't work for you? – mankoff May 15 '20 at 14:30
0

You can use (use-package exwm ... ) multiple times. That might help.

2
  • 1
    Maybe but doesn't that defeat the purpose of use-package? I thought it was to keep the configuration of the package all in one place (but I don't use it, so this may be a wee bit off...) – NickD Apr 6 '20 at 0:27
  • I think use-package is more general than that. There are other purposes, like tighter syntax. And there may be logical reasons to not keep things in one place, and this supports that elegantly. – mankoff Apr 7 '20 at 16:19
0

You have two issue here and probably should have 2 questions. First is indent second is bracket matching for smartparens

You can indent the whole tangled source file after saving it. This idea is taken from https://github.com/grettke/help

The relevant code is

(defun help/org-babel-post-tangle-hook-fn ()
  (interactive)
  (indent-region (point-min) (point-max) nil)
  (save-buffer))
(add-hook 'org-babel-post-tangle-hook #'help/org-babel-post-tangle-hook-fn)

To deal with the bracket issue I would look at weaving and literate programming https://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming and the grettke link so that each code block is balanced e.g.

#+BEGIN_SRC elisp
(use-package exwm
  :config
  (exwm-enable)
<<exwm>>
) ; close use-package
#+END_SRC

and

#+BEGIN_SRC elisp :tangle no :noweb-ref exwm
  :init
  (setq exwm-workspace-number 4
        exwm-workspace-show-all-buffers t
        exwm-layout-show-all-buffers t) ; parens balanced in code block
#+END_SRC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.