[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: major mode for fpscalc + some meta
From: |
Emanuel Berg |
Subject: |
Re: major mode for fpscalc + some meta |
Date: |
Wed, 02 Oct 2013 02:19:54 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
OK, I hope to close the book on this with this last fix.
First, to get indentation, I derived the mode from the C
mode. Because the syntaxes are so close, I thought that
would work. And it did.... except for the M-; "!"
comment. Such comments could be inserted on M-;, but not
*removed*, instead, I got another comment layer, just
like the nested quotes in messages.
Also, comments broke indentation.
So, I dropped the C mode, and the comments worked both
ways. Last, I used some material I found on the web to
get indentation. (The code below is very close to what I
found.)
(You have to have indentation. "May I indent your code?"
is still the worst hacker insult in the book, a book
that by now has quite a heft... Seriously, it stinks
without it: half the time you just match lines.)
I include the new code below, if you don't care to get
the real file.
I wonder... I got lots of help on this. Personally, I
never care for credit because I always use whatever I
want, and I expect everyone else to do the same with my
stuff. But, if you guys want me to mention "thanks to
the GEH people" I'll add it, of course.
Last, I made an example in LaTeX how to create diagrams,
that can be used in connection with fpscalc, diagrams
such as this:
http://user.it.uu.se/~embe8573/cis/1-5.pdf
The LaTeX source, and more on this:
http://user.it.uu.se/~embe8573/cis/
(I write this, as this post might by Googled for
fpscalc, and lots of poor students, held at starvation
point by the pitch-dark computer industry, might benefit
from both the Emacs mode, and the diagram LaTeX skeleton
code.)
OK, back to the Emacs mode:
All material, including screenshots and readmes:
http://user.it.uu.se/~embe8573/fps/
The mode code:
http://user.it.uu.se/~embe8573/fps/fpscalc.el
Example data to edit/run:
http://user.it.uu.se/~embe8573/fps/demo.fps
The new code:
(define-generic-mode
'fpscalc-mode
'("!")
nil
fpscalc-keywords
'("\\.fps\\'")
'((lambda ()
(progn
(setq indent-line-function 'fpscalc-indent-line)
(local-set-key "\C-c\C-c" 'compute) )))
"Major mode for .fps files and the fpscalc tool.")
(defvar fpscalc-mode-map
(let ((the-map (make-keymap)))
(define-key the-map (kbd "TAB") 'newline-and-indent)
the-map)
"Keymap for the fpscalc major mode.")
(defun fpscalc-indent-line ()
"Indentation function."
(interactive)
(beginning-of-line)
(if (bobp) (indent-line-to 0)
(let ((not-indented t)
(cur-indent 0)
(indent-unit 2))
(if (looking-at "^[ \t]*}")
(progn
(save-excursion
(forward-line -1)
(setq cur-indent (- (current-indentation) indent-unit) ))
(if (< cur-indent 0) (setq cur-indent 0)) )
(save-excursion
(while not-indented
(forward-line -1)
(if (looking-at "^[ \t]*}")
(progn
(setq cur-indent (current-indentation))
(setq not-indented nil) )
(if (looking-at "^[
\t]*\\(system\\|declarations\\|semaphores\\|initialise\\|formulas\\)")
(progn
(setq cur-indent (+ (current-indentation) indent-unit))
(setq not-indented nil) )
(if (bobp) (setq not-indented nil) ))))))
(indent-line-to cur-indent) )))
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
- Re: major mode for fpscalc + some meta,
Emanuel Berg <=