Skip to content

Another Emacs configuration in org

Here. It is nice.

My apologies for forgetting how I ended up here.

21 Comments

  1. Will wrote:

    Grant, thanks for sharing this example. At the risk of asking what may be a question with a very obvious answer, have you shared your process for exporting this configuration from org-mode (init.org) to what appears to be a plain text file (init.el). I’m keen to learn how you embedded all the org headings and text into a comments region and how you managed to keep your elisp out of that region. Thanks!

    Monday, July 14, 2014 at 07:39 | Permalink
  2. Grant wrote:

    WILL:

    This is not my example but I may be able to explain it.

    In ‘init.org’, the header arguments ‘:tangle yes’ will ask org-mode create output to a file of the type specified by the source blocks, which in this file is all emacs-lisp. When ‘tangle-init’ is called, it will convert that org file into the init.el file

    Monday, July 14, 2014 at 13:36 | Permalink
  3. Will wrote:

    Grant, thanks so much for your reply! I have not used tangle but I’m guessing that ‘tangle-init’ is not customized and just comes standard with the tangle package, correct? If that’s the case, then it sounds like my next step will be to learn how to use tangle to “export” from org to elisp. This is really a great idea. I’ve made efforts to draft meaningful and concise comments in my .emacs file but it’s not as easy to browse anymore. I’m hoping this will work as a method to do the same.

    Monday, July 14, 2014 at 14:23 | Permalink
  4. Grant wrote:

    WILL:

    ‘tangle-init’ is the authors custom function in that file. ‘org-babel-tangle’ is the built in function that does the tangling. There are a lot of posts out there of different folks approaches. Mine is here https://github.com/grettke/home

    Monday, July 14, 2014 at 17:35 | Permalink
  5. Will wrote:

    I see now. I’ve never created my own function definitions in elisp so I didn’t know to look for it. But it’s there as you described.

    After reviewing it, I think I probably need to go back and review the diff between init.el and .emacs. I really like the approach that both you and the author have taken in using org files to generate your configs. Thanks!

    Monday, July 14, 2014 at 20:18 | Permalink
  6. Lars wrote:

    Hi, author here.

    I thought I could add to Grant’s reply (to the first question). By default tangle does not include text or headings as comments. It’s the `:comments org’-part of the header-args line that enables this.

    #+PROPERTY: header-args :tangle yes :comments org

    Tuesday, July 15, 2014 at 09:27 | Permalink
  7. Will wrote:

    Hello Lars, thanks for you reply. I really like your example. So, it sounds like `:comments org’ takes everything that’s not in between ‘#+BEGIN_SRC’ and ‘#+END_SRC’ including all the org-mode headings, subheadings, and comments and comments them out in the resulting elisp file. Thanks. Maybe using tangle is simpler than I realized.

    Tuesday, July 15, 2014 at 09:33 | Permalink
  8. Lars wrote:

    Thanks!

    The “meta” part of the config is all I’ve included to make sure the init-file is tangled. So I would second that it’s quite simple!

    Tuesday, July 15, 2014 at 16:11 | Permalink
  9. Will wrote:

    OK, I just gave this a try. But I’m not quite sure it’s working yet. So I opened up the init.org file, C-c C-v t per your instructions, and the message read:

    (No changes need to be saved)
    Tangled 0 code blocks from init.org

    Surely I’m missing something simple. Can you advise me how to being troubleshootint?

    Tuesday, July 15, 2014 at 18:18 | Permalink
  10. Lars wrote:

    The #+PROPERTY-line mentioned earlier needs to be loaded when it’s first added. You can do this by `C-c C-c’ when the point is at that line. It should not be necessary to do this when you open the file later.

    If that’s isn’t the problem, please post your code!

    Wednesday, July 16, 2014 at 06:34 | Permalink
  11. Will wrote:

    Lars, here’s what I tried:

    1. I saved init.org to ~/Desktop and opened it in Emacs. At the time I did so, I had already safely backed up and removed my existing .emacs and init.el files from their respective locations.

    2. I opened init.org and C-c C-c on the #+PROPERTY line as you described. BTW, init.org is the same file that I downloaded from your github resource. I made no changes. After that, I got this message:

    Local setup has been refreshed
    CHILDREN
    SUBTREE (NO CHILDREN)
    Evaluate this emacs-lisp code block on your system? (y or n) y
    executing Emacs-Lisp code block…
    Code block evaluation complete.

    3. In init.org, I did C-c C-v t. And got this message:

    Tangled 0 code blocks from init.org

    I also got a symlink in the same location as init.org which had no target.

    So, I think I’m one step closer to generating a init.el file from your init.org file but I’m not there yet. I didn’t post the code since it’s identical to yours but I can do so.

    Thanks for your help!

    I tried this three more times with the same result.

    Wednesday, July 16, 2014 at 06:51 | Permalink
  12. Lars wrote:

    OK, I think it’s the org-version (tried tangling with `emacs -q’ and got the same result as you).

    Try installing org verison 8 (or higher). BTW, if you run the init.el file (already tangled when cloned), it should install the newest version of org-mode (and lots of other packages).

    Wednesday, July 16, 2014 at 06:59 | Permalink
  13. Will wrote:

    Lars, I updated to org-mode 8.2.7b and then reloaded org-mode to ensure that it was running correctly.

    Next I tried C-c C-c on the #+PROPERTY line. I got the following result:

    org-indent-add-properties: Invalid function: org-with-silent-modifications [2 times]

    Wednesday, July 16, 2014 at 07:09 | Permalink
  14. Will wrote:

    Lars, I’m beginning to think that the problem is with some conflict in my older and newer org installations. I think that it’s possible I may have used two diff installation methods but I’m not sure. At any rate, I think your example is awesome and I can’t wait to try it out. But I think I’ll need to go back and clean up my org-mode install or my Emacs to get this working correctly.

    Before I proceed, do you have any advice on the best method for maintaining an updated but not bleeding edge version of org? I’d prefer to just use package installation but I suppose it might make sense to build from source.

    Thanks again for your help!

    Wednesday, July 16, 2014 at 07:20 | Permalink
  15. Lars wrote:

    I use package-install. I keep all packages updated by having Emacs prompt me to update every week (part of the package section in the config), and this includes org as well.

    Wednesday, July 16, 2014 at 07:38 | Permalink
  16. Will wrote:

    Lars, after backing everything up, I just reinstalled Emacs, re-opened Emacs with your init.el file and let it run the updates. Magic! This is really great.

    Wednesday, July 16, 2014 at 08:02 | Permalink
  17. Will wrote:

    Lars, I have one more question for you. there seem to be two methods of generating init files: 1)auto-compile function which is invoked after saving a file and appears to generate an init.elc and 2) C-c C-v t which generates an init.el. Assuming I’m correct, I’m wondering if these two will conflict. Any ideas how I can avoid this?

    Wednesday, July 16, 2014 at 09:13 | Permalink
  18. Lars wrote:

    I’m glad you like it!

    Normally you’d want to tangle an org-file by using `C-c C-v t’; this should write an .el-file.

    I thought it might get tedious to do this procedure each time I change my config-file, so I added a function (named `tangle-init’) that runs each time you save a file. This function tangles the source blocks into a file called `init.el’, and byte-compiles this resulting in a file called `init.elc’.

    Hope this answered your question!

    Wednesday, July 16, 2014 at 14:27 | Permalink
  19. Will Monroe wrote:

    Lars, I’ve had some time to get this working today and it’s going very smoothly. I disabled the byte-compile option for fear that I might create a conflict between the init.el and init.elc files. What will Emacs do when it encounters two of this in the same .emacs.d directory?

    Wednesday, July 16, 2014 at 14:46 | Permalink
  20. Lars wrote:

    Emacs always chooses .elc-files for loading, because it’s faster. So if you don’t plan on compiling, init.elc should be deleted.

    I don’t run into problems with it because I always edit the init.org-file, and generate both an init.el and an init.elc. If you, however, want to edit the init.el file directly, the changes you make won’t take affect when you restart Emacs (because Emacs is actually loading the init.elc).

    But remember that if you change you’re init.el directly, then you could loose these changes by tangling the init.org file.

    Wednesday, July 16, 2014 at 15:05 | Permalink
  21. Will Monroe wrote:

    I understand. Thanks. I’ve uncommented it in my init.org now but it doesn’t seem to compile after save. But on the bright side, your defun makes sense to me now. I’m a lisp beginner but I’m starting to get the hang of reading them.

    Wednesday, July 16, 2014 at 16:25 | Permalink

One Trackback/Pingback

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*