ledger-fontify.el (2014B)
1 ;;; ledger-fontify.el --- Provide custom fontification for ledger-mode -*- lexical-binding: t; -*- 2 3 4 ;; Copyright (C) 2014 Craig P. Earls (enderw88 at gmail dot com) 5 6 ;; This file is not part of GNU Emacs. 7 8 ;; This is free software; you can redistribute it and/or modify it under 9 ;; the terms of the GNU General Public License as published by the Free 10 ;; Software Foundation; either version 2, or (at your option) any later 11 ;; version. 12 ;; 13 ;; This is distributed in the hope that it will be useful, but WITHOUT 14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 ;; for more details. 17 ;; 18 ;; You should have received a copy of the GNU General Public License 19 ;; along with GNU Emacs; see the file COPYING. If not, write to the 20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 21 ;; MA 02110-1301 USA. 22 23 ;;; Commentary: 24 ;; Font-lock-mode doesn't handle multiline syntax very well. This 25 ;; code provides font lock that is sensitive to overall transaction 26 ;; states 27 28 29 ;;; Code: 30 31 (require 'ledger-navigate) 32 (require 'ledger-regex) 33 (require 'ledger-state) 34 35 ;; These are dynamically bound, see `font-lock-extend-region-functions'. 36 (defvar font-lock-beg) 37 (defvar font-lock-end) 38 39 (defcustom ledger-fontify-xact-state-overrides nil 40 "If t the highlight entire xact with state." 41 :type 'boolean 42 :group 'ledger) 43 44 (defun ledger-fontify-extend-region () 45 "Extend fontification region to include whole transactions or directives." 46 (save-match-data 47 (let* ((new-beg (min font-lock-beg (car (ledger-navigate-find-element-extents font-lock-beg)))) 48 (new-end (max font-lock-end (cadr (ledger-navigate-find-element-extents font-lock-end)))) 49 (changed (or (/= new-beg font-lock-beg) 50 (/= new-end font-lock-end)))) 51 (setq font-lock-beg new-beg) 52 (setq font-lock-end new-end) 53 changed))) 54 55 56 (provide 'ledger-fontify) 57 58 ;;; ledger-fontify.el ends here