I'm writing a `shell-session-mode` to be able to create org-mode source blocks similar to GitHub Flavored Markdown's:
```console
$ command
output
more output
$ another command
output
...
```
All I want is for the `$ command`s to be colorized. I haven't created an emacs mode before so I'm following https://stackoverflow.com/questions/14885670/create-a-new-mode-in-emacs and of course the Emacs Lisp info pages.
However when I try to use the mode in org mode's source block:
#+begin_src shell-session
#+end_src
I immediately get the error in the Emacs mode line:
Org mode fontification error in #<buffer foo.org> at 22
I can't seem to invoke a debugger at this error. Using `(setq debug-on-error t)` seems to have no effect.
Here is my `shell-session-mode.el` file:
;;; shell-session --- Markup shell commands with their output.
;;;
;;; Commentary:
;;;
;;; Colorizes blocks similar to "console" in GitHub Flavored Markdown
;;; which is defined as "ShellSession" in
;;; https://github.com/github/linguist which uses the regexp in:
;;; https://github.com/atom/language-shellscript/blob/master/grammars/shell-session.cson
;;;
;;; Code:
;;;
;;; Include this in your .emacs init file:
;;;
;;; (require 'shell-session-mode)
(defcustom shell-session-prompt-regexp
(regexp-quote "^[^[:space:]]*$[[:space:]]+[^[:space:]]+$")
"Regexp matching a shell $ prompt with a command."
:type 'regexp
:group 'shell-session)
(define-derived-mode shell-session-mode fundamental-mode "shell-session-mode"
"A major mode to display shell sessions."
:group 'shell-session
(font-lock-add-keywords
nil
'((shell-session-prompt-regexp . font-lock-keyword-face))))
(add-to-list 'auto-mode-alist '("\\.sh-session\\'" . shell-session-mode))
(provide 'shell-session-mode)
;;; shell-session-mode.el ends here.
I have the file located in my `~/.emacs.d/lisp` and load it with use-package:
(use-package shell-session-mode
:load-path "lisp"
:ensure nil)