Question re: Templating and (insert-file-contents)Hey everyone. I had a quick question here regardi…
انتشار: 2026/07/14 17:07 UTC
Question re: Templating and (insert-file-contents)Hey everyone. I had a quick question here regarding abbrev-mode, templating, and really just Elisp broadly. I'm a teacher and am attempting to automate a really simply thing I do every semester: create a file with a week by week template. The intended workflow is extremely simple: prompt the user for some metadata and insert the contents of a template file.I used to use yasnippet for this and it worked perfectly. But this is essentially the only thing I use yasnippet for, so I challenged myself to recreate it using abbrev-mode and a basic Elisp function. The problem is that (insert-file-contents) inserts the contents after the current point according to the documentation, and this messes up the first line of the inserted org-mode text, as you'll see below.Here's the relevant function: (defun course-template () (interactive) (insert (format "#+TITLE: %s" (read-string "course name: "))) (newline) (insert-file-contents "~/Org/templates/tpl-course-template.org")) (define-abbrev global-abbrev-table "abcourse" "" 'course-template)And here's the template text. (It's unfinished but I'm just trying to figure out the issue.) Week 1 Tuesday ThursdayFinally, here is the output of the function (note how the first heading includes a space before the first character): Week 1 Tuesday ThursdayThose familiar with org-mode will know that this extra spaces breaks Emacs's ability to treat that first line as an actual heading. I'm wondering if anyone has any insight on how to get the file to insert at the current point, rather than after it, to avoid this. Thanks in advancearedd.it/1uwdlar@r_emacs


