reddit / emacs

Can somebody help me make a change to the syntax in fountain-mode?

Lindisfritjof · 2022-02-15 20:27
I am writing a radio drama in the markdown style known as "fountain-mode" in emacs, and I really miss a way to make Sound Effects stand out. Fountain was originally made for Screenplays, but I'd love to be able to type something like FX: And then have the following words underscored and in all caps until a manual line-break. Does anybopdy know how I can write that function into the mode? Is there an elisp-way to do it?
EcstaticBill2638 · 2022-02-16 00:02
I had an inexpert go at this (defun fountain-match-fx () (save-excursion (beginning-of-line) (and (looking-at "^fx: ") (fountain-blank-before-p)))) (defun fountain-match-fx-underscore-bol () (save-excursion (beginning-of-line) (and (looking-at "^fx: _") (fountain-blank-before-p)))) (defun fountain-match-fx-underscore-eol () (save-excursion (end-of-line) (backward-char) (and (looking-at "_$") (fountain-blank-before-p)))) (defun fountain--auto-markup-fx () (when (fountain-match-fx) (unless (fountain-match-fx-underscore-bol) (replace-regexp "^fx: " "fx: _" nil (line-beginning-position) (line-end-position))) (unless (fountain-match-fx-underscore-eol) (save-excursion (end-of-line) (insert-char ?\_))) (upcase-region (line-beginning-position) (or (match-end 2) (point))))) (add-hook 'post-self-insert-hook #'fountain--auto-markup-fx) should add underscores and upper-case to any line starting with "fx: "
Lindisfritjof · 2022-02-16 06:17
Thank you so much!Where should I put this? In .emacs or somewhere like that, or should I try to find the correct fountain-code-file and put it there? Edit: I found out! It sort of works :) - the only minor issue is that fountain treats it as a character, if one doesn't make two spaces below. But that really is minor, and probably has to do with a deeper function in fountain. Again: Thank you SO much for this! !
EcstaticBill2638 · 2022-02-16 09:52
Glad it works, I would put it in a `use-package` statement in your init file, like so (use-package fountain-mode :config insert-code-here ) I think I see what you mean with the character issue, it seems to only happen for me when I add a newline from inside the underscores, but not if I go to the end of the line first and then newline. Might be worth binding return to something like this in `fountain-mode`? (defun end-of-line-and-newline () "Add a newline from the end of the current line." (interactive) (end-of-line) (newline-and-indent))