I've cleaned up the regular expressions, made the number regexes
more specific to dates and times. I also made some cosmetic changes to
the file so hopefully it is easier to understand.
However one problem I can't seem to overcome is the
unwanted colourisation of days and months after the MSG command. Elisp
regular expressions don't have lookaround structures and my regexp mojo
is not good enough to work out how to mimic it.
Also I have not tested this file with the latest remind, so there
might be some new functions, structures that it doesn't take into
account. Let me know if this is the case.
Also Hendrick asked for some easy to enter days like four days from
now, tomorrow etc.
I did today, but though I did look around for some clues of how to do
the other suggestions, I'm afraid my elisp skills are not enough to
tackle these others. Maybe if I keep thinking about this I may be able
to achieve it eventually.
Let me know how it works.
Shelagh
--
----------------------------------------------------------------
Jabber: [EMAIL PROTECTED]
----------------------------------------------------------------
;;; remind-conf-mode.el --- A mode to help configure remind.
;; Copyright (C) 2008 Shelagh Manton <[EMAIL PROTECTED]>
;; Author: Shelagh Manton <[EMAIL PROTECTED]> with help from
;; David F. Skoll
;; Keywords: remind configure mode
;; Version: .03
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.
;;; Commentary:
;; Use this mode to help with the configuration of remind configuration files.
;; Put (require 'remind-conf-mode) in your .emacs file
;; also put (add-to-list 'auto-mode-alist '("\\.rem\\'" . remind-conf-mode))
;; (add-to-list 'auto-mode-alist '("~/.reminders" . remind-conf-mode)) if you
;; want to have the mode work automatically when you open a remind configuration file.
;;; History:
;; Thu, Feb 14, 2008
;; Based mode on wpld-mode tutorial and sample-mode on emacs wiki.
;; Ideas from mupad.el for font-lock styles.
;;; Code:
(require 'font-lock); this goes in the define-derived-mode part.
(require 'regexp-opt)
(defgroup remind-conf nil
"Options for remind-conf-mode."
:group 'remind-conf
:prefix "remind-conf-")
;; (defvar remind-conf-font-lock-keywords remind-conf-font-lock-keywords-3
;; "Default highlighting for `remind-conf-mode'.")
(defvar remind-conf-mode-hook nil
"Hook to run in `remind-conf-mode'.")
;; keymap
(defvar remind-conf-mode-map
(let ((remind-conf-mode-map (make-sparse-keymap)))
remind-conf-mode-map)
"Keymap for `remind-conf-mode'.")
(define-key remind-conf-mode-map "\C-cr" 'rem-skel)
(define-key remind-conf-mode-map "\C-ct" 'rem-today)
(define-key remind-conf-mode-map "\C-cd" 'rem-today-skel)
;; syntax-table
(defvar remind-conf-syntax-table
(let ((remind-conf-syntax-table (make-syntax-table text-mode-syntax-table)))
;Comments are the same as Lisp
(modify-syntax-entry ?\; ". 1b" remind-conf-syntax-table); the . works better
; than < as this interferes with the strings.
(modify-syntax-entry ?\# ". 1b" remind-conf-syntax-table)
(modify-syntax-entry ?\n "> b" remind-conf-syntax-table)
;Names with _ are still one word.
(modify-syntax-entry ?_ "w" remind-conf-syntax-table)
(modify-syntax-entry ?. "w" remind-conf-syntax-table);makes a fullstop part of
;word syntax. File extensions don't show up
;as a keyword.
; we do use various sorts of braces.
(modify-syntax-entry ?\( "()" remind-conf-syntax-table)
(modify-syntax-entry ?\) ")(" remind-conf-syntax-table)
(modify-syntax-entry ?\[ "(]" remind-conf-syntax-table)
(modify-syntax-entry ?\] ")[" remind-conf-syntax-table)
remind-conf-syntax-table)
"Syntax table for `remind-conf-mode'.")
;; faces
;;example of setting up special faces for a mode.
(defvar remind-conf-command-face 'remind-conf-command-face
"Remind commands.")
(defface remind-conf-command-face
'((t :foreground "SeaGreen4" :bold t))
"Font Lock mode face used to highlight commands."
:group 'face)
(defvar remind-conf-keyword-face 'remind-conf-keyword-face
"Remind keywords.")
(defface remind-conf-keyword-face
'((t :foreground "blue violet"))
"Font Lock mode face used to highlight keywords."
:group 'face)
(defvar remind-conf-substitutes-face 'remind-conf-substitutes-face
"Remind substitutes.")
(defface remind-conf-substitutes-face
'((t :foreground "blue2"))
"Font Lock mode face used to highlight substitutes."
:group 'face)
(defvar remind-conf-endline-face 'remind-conf-endline-face
"Remind endline.")
(defface remind-conf-endline-face
'((t :foreground "goldenrod2" :bold t))
"Font Lock mode face used to highlight commands."
:group 'face)
(defvar remind-conf-variable-face 'remind-conf-variable-face
"Remind variable.")
(defface remind-conf-variable-face
'((t :foreground "DeepPink2" :bold t))
"Font Lock mode face used to highlight commands."
:group 'face)
(defvar remind-conf-color-face 'remind-conf-color-face
"Remind color variables.")
(defface remind-conf-color-face
'((t :foreground "gold" :bold t))
"Font Lock mode face used to highlight color changes."
:group 'face)
(defvar remind-conf-delta-face 'remind-conf-delta-face
"Remind deltas.")
(defface remind-conf-delta-face
'((t :foreground "sandy brown" :bold t))
"Font Lock mode face used to highlight deltas."
:group 'face)
(defvar remind-comment-face 'remind-comment-face
"Remind comments.")
(defface remind-comment-face
'((t :foreground "brown"))
"Font-lock face for highlighting comments."
:group 'face)
(defvar remind-string-face 'remind-string-face
"Remind strings.")
(defface remind-string-face
'((t :foreground "salmon"))
"Font lock mode face used to highlight strings."
:group 'face)
(defvar remind-time-face 'remind-time-face
"Remind time words.")
(defface remind-time-face
'((t :foreground "LightSeaGreen" :bold t))
"Font lock mode face to highlight time phrases."
:group 'face)
;; complex regexp variables
(defvar rem-months "\\(A\\(?:PR\\(?:IL\\)?\\|UG\\(?:UST\\)?\\)\\|DEC\\(?:EMBER\\)?\\|FEB\\(?:RUARY\\)?\\|J\\(?:AN\\(?:UARY\\)?\\|U\\(?:LY\\|NE\\|[LN]\\)\\)\\|MA\\(?:RCH\\|[RY]\\)\\|NOV\\(?:EMBER\\)?\\|OCT\\(?:OBER\\)?\\|SEP\\(?:T\\(?:EMBER\\)?\\)?\\)" "Regexp for months")
(defvar rem-days "\\(FRI\\(?:DAY\\)?\\|MON\\(?:DAY\\)?\\|S\\(?:AT\\(?:URDAY\\)?\\|UN\\(?:DAY\\)?\\)\\|T\\(?:HU\\(?:R\\(?:S\\(?:DAY\\)?\\)?\\)?\\|UE\\(?:S\\(?:DAY\\)?\\)?\\)\\|WED\\(?:NESDAY\\)?\\)" "Regexp for days")
(defvar rem-keywords "\\(CAL\\|FSET\\|MS[FG]\\|OMIT\\|PS\\(?:FILE\\)?\\|R\\(?:EM\\|UN\\)\\|S\\(?:ATISFY\\|ET\\|HADE\\|PECIAL\\)\\|TRIGGER\\)" "Regexp for keywords")
(defvar rem-commands "\\(A\\(?:FTER\\|T\\)\\|B\\(?:ANNER\\|EFORE\\)\\|DURATION\\|INCLUDE\\|ONCE\\|P\\(?:RIORITY\\|USH_OMIT_CONTEXT\\)\\|S\\(?:C\\(?:ANFROM\\|HED\\)\\|KIP\\)\\|TAG\\|UN\\(?:SET\\|TIL\\)\\|WARN\\)" "Regexp for commands")
;; keywords
(defconst remind-conf-font-lock-keywords-1
(list
'("^[\;\#]\\s-+.*$" . remind-comment-face)
'("\\<"rem-keywords"\\>" . remind-conf-keyword-face)
'("%[\"_]" . font-lock-warning-face)
'("\\<%[abcefghijkluv]" . remind-conf-substitutes-face)
'("\"[^\"]*\"" . remind-string-face))
"Minimal font-locking for `remind-conf-mode'.")
(defconst remind-conf-font-lock-keywords-2
(append remind-conf-font-lock-keywords-1
(list
'("\\<"rem-months"\\>" . remind-time-face)
'("^SET\\s-+\\<"rem-months"\\>" 1 remind-time-face)
'("^"rem-days"\\>" . remind-time-face)
'("\\<"rem-days"\\>" . remind-time-face)
'("^SET\\s-+\\<"rem-days"\\>" 1 remind-time-face)
'("\\<"rem-commands"\\>" . remind-conf-command-face)
'("%$" . remind-conf-endline-face)
'("\\s-+\\([+-][+-]?[1-9][0-9]*\\)\\s-+" . remind-conf-delta-face)))
"Additional commands to highlight in `remind-conf-mode'.")
(defconst remind-conf-font-lock-keywords-3
(append remind-conf-font-lock-keywords-2
(list
'("\\<\\(INT\\|STRING\\|TIME\\|DATE\\)\\>" . remind-conf-type-face )
'("\[[a-zA-Z]+\]" . remind-conf-color-face)
'("\\s-+\\([0-2]?[0-9]\\|3[01]\\)\\s-+" 1 remind-time-face);better date regexp
'("\\s-+\\([12][0-9][0-9][0-9]\\)\\s-+" 1 remind-time-face);years
'("\\<AT\\> \\([01]?[0-9]:[0-5][0-9]\\|2[0-4]:[0-5][0-9]\\)\\s-+" 1 remind-time-face) ;24hour clock, more precise
'("\\<\$[A-Za-z]+\\>" . remind-conf-variable-face)))
"The ultimate in highlighting experiences for `remind-conf-mode'.")
(defcustom remind-conf-font-lock-keywords 'remind-conf-font-lock-keywords-3
"Font-lock highlighting level for `remind-conf-mode'."
:group 'remind-conf
:type '(choice (const :tag "Barest minimum of highlighting." remind-conf-font-lock-keywords-1)
(const :tag "Medium highlighting." remind-conf-font-lock-keywords-2)
(const :tag "Highlighting deluxe." remind-conf-font-lock-keywords-3)))
;; thank goodness we don't have to worry about indentation.
;; however I can do a skeleton for convenience of new users.
(define-skeleton rem-skel
"Skeleton to insert a rem line in a remind configuration file."
nil
"REM "(skeleton-read "Date? " )
("Optional: How many days ahead? " " +" str )
resume:
("Optional: At what time? Format eg 13:00. " " AT " str)
resume:
("Optional: How many minutes ahead? " " +" str )
resume:
("Optional: At what priority? eg 0-9999" " PRIORITY " str )
resume:
" MSG %\"" (skeleton-read "Your message? " )"%b%\"%" \n
)
(define-skeleton rem-today-skel
"Skeleton to insert a line for today's date."
nil
"REM " (format-time-string "%d %b %Y")
("Optional: At what time? Format eg 13:20. " " AT " str)
resume:
("Optional: How many minutes ahead? " " +" str )
resume:
("Optional: At what priority? eg 0-9999" " PRIORITY " str )
resume:
" MSG " (skeleton-read "Your message? " )"%b.%" \n
)
(setq skeleton-end-hook nil)
(defun rem-today ()
"Insert the date for today in a remind friendly style."
(interactive)
(insert (format-time-string "%d %b %Y")))
;; finally the derived mode.
;;;###autoload
(define-derived-mode remind-conf-mode text-mode "remind-conf-mode"
"Major mode for editing remind calendar configuration files."
:syntax-table remind-conf-syntax-table
(set (make-local-variable 'font-lock-defaults) '(remind-conf-font-lock-keywords))
(set (make-local-variable 'font-lock-keywords-case-fold-search) 't)
(set (make-local-variable 'comment-start) ";")
(set (make-local-variable 'comment-start) "#")
(set (make-local-variable 'comment-end) "\n")
(set (make-local-variable 'fill-column) '100);cause I was having problems with autofill.
; (set (make-local-variable 'auto-fill-mode) -1) ;or maybe turn autofill off in this mode.
(use-local-map remind-conf-mode-map)
)
(provide 'remind-conf-mode)
;;; remind-conf-mode.el ends here
_______________________________________________
Remind-fans mailing list
[email protected]
http://lists.whatexit.org/mailman/listinfo/remind-fans