1 ;;; pspp-mode-el -- Major mode for editing PSPP files
4 ;; Author: John Darrington <john@darrington.wattle.id.au>
5 ;; Created: 05 March 2005
6 ;; Keywords: PSPP major-mode
8 ;; Copyright (C) 2005 John Darrington
10 ;; Based on the example wpdl-mode.el by Scott Borton
11 ;; Author: Scott Andrew Borton <scott@pp.htv.fi>
13 ;; Copyright (C) 2000, 2003 Scott Andrew Borton <scott@pp.htv.fi>
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2 of
18 ;; the License, or (at your option) any later version.
20 ;; This program is distributed in the hope that it will be
21 ;; useful, but WITHOUT ANY WARRANTY; without even the implied
22 ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
23 ;; PURPOSE. See the GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public
26 ;; License along with this program; if not, write to the Free
27 ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 (defvar pspp-mode-hook nil)
33 (let ((pspp-mode-map (make-keymap)))
34 (define-key pspp-mode-map "\C-j" 'newline-and-indent)
36 "Keymap for PSPP major mode")
38 (add-to-list 'auto-mode-alist '("\\.sps\\'" . pspp-mode))
41 (defun pspp-data-block ()
42 "Returns t if current line is inside a data block."
47 (begin-data-found nil)
53 (while (not (or (bobp) end-data-found) )
55 (if (looking-at "^[ \t]*END +DATA\.")
56 (setq end-data-found t)
61 (if (looking-at "^[ \t]*BEGIN +DATA\.")
62 (setq begin-data-found t)
68 (setq inside-block (and begin-data-found (not end-data-found)))
76 (defun pspp-indent-line ()
77 "Indent current line as PSPP code."
82 (the-indent 0) ; Default indent to column 0
86 (setq the-indent 0) ; First line is always non-indented
95 ;; If the most recent non blank line ended with a `.' then
96 ;; we're at the start of a new command.
99 (while (and blank-line (not (bobp)))
102 (if (and (not (pspp-data-block)) (not (looking-at "^[ \t]*$")))
104 (setq blank-line nil)
106 (if (not (looking-at ".*\\.[ \t]*$"))
107 (setq within-command t)
113 (if within-command (setq the-indent 8) )
118 (if (not (pspp-data-block)) (indent-line-to the-indent))
123 (defvar pspp-mode-syntax-table
125 (x-pspp-mode-syntax-table (make-syntax-table))
128 (modify-syntax-entry ?_ "w" x-pspp-mode-syntax-table)
129 (modify-syntax-entry ?. "w" x-pspp-mode-syntax-table)
130 (modify-syntax-entry ?\" "|" x-pspp-mode-syntax-table)
131 (modify-syntax-entry ?\' "|" x-pspp-mode-syntax-table)
133 ;; Comment definitions
134 (modify-syntax-entry ?* "<\n" x-pspp-mode-syntax-table)
136 ;; (modify-syntax-entry ?\n "- 1" x-pspp-mode-syntax-table)
137 ;; (modify-syntax-entry ?* ". 2" x-pspp-mode-syntax-table)
139 (modify-syntax-entry ?\n ">*" x-pspp-mode-syntax-table)
141 x-pspp-mode-syntax-table)
143 "Syntax table for pspp-mode")
147 (kill-all-local-variables)
148 (use-local-map pspp-mode-map)
149 (set-syntax-table pspp-mode-syntax-table)
150 (setq comment-start "* ")
151 ;; Register our indentation function
152 (set (make-local-variable 'indent-line-function) 'pspp-indent-line)
153 (setq major-mode 'pspp-mode)
154 (setq mode-name "PSPP")
155 (run-hooks 'pspp-mode-hook))
159 ;;; pspp-mode.el ends here