* major mode for fpscalc + some meta
@ 2013-09-22 14:45 Emanuel Berg
2013-09-22 18:32 ` Stefan Monnier
[not found] ` <mailman.2705.1379874790.10748.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-09-22 14:45 UTC (permalink / raw)
To: help-gnu-emacs
I'm giving this group a third shot. I have a new
strategy for not getting into flame wars. That's meta,
so I won't go into details, but trust me, I'll not get
into another flame war as true as the Earth makes one
revolution around the sun in 365.25 days.
Another side note: I changed my mind, Juanma was right
in saying that C++ in all honesty cannot be described as
"straightforward".
OK, not dwelling on the past ...
I wanted to share this with you: I made a major mode for
the tool fpscalc. fpscalc (fps = fixed priority
schedulability) is a tool that computes response times
and workloads for tasks and real time systems, in order
to do schedulability analysis (i.e., will all tasks
complete prior to their deadlines?).
Have a look at the dump [1] to get a feeling what it is
all about.
The mode includes:
1. Very ambitious font lock - looks like a circus at
first, but once you get used to it, it is very
useful. (I didn't use the font-lock faces because I
want everything to be configurable on a
per-mode/-application/whatever basis.)
2. Comment and uncomment with M-;
3. Indentation (very easy - I just used the C mode ditto
- but nonetheless, it is there)
4. A defun ("compute") to run the tool from a script
(shown in Emacs), and then have Emacs show the result
of fpscalc crunching that script.
I didn't had any "professional" material to guide me, so
I just made it work as I always do, by being active,
making it work by outworking the opposition. Therefore,
there might be some formal stuff missing to make it a
"real" major mode. If so, please make me aware of it.
Unlike all my other Emacs hacking, this is something
that will be used not just by me but by dedicated,
serious people, so I would be very appreciative if you
gave me feedback.
Note on the dump: It turns out, fbcat produces PPM
files, and not PNG. I used ppmtobmp to make a BMP of
it. It really doesn't matter; I say it just so you won't
be confused by the inconsistency of the filename and the
shell command extensions.
[1 - dump]
http://user.it.uu.se/~embe8573/fps/fpscalc_mode.bmp
[source]
http://user.it.uu.se/~embe8573/fps/fpscalc.el
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: major mode for fpscalc + some meta
2013-09-22 14:45 major mode for fpscalc + some meta Emanuel Berg
@ 2013-09-22 18:32 ` Stefan Monnier
2013-09-22 23:07 ` Suvayu Ali
[not found] ` <mailman.2705.1379874790.10748.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2013-09-22 18:32 UTC (permalink / raw)
To: help-gnu-emacs
> I wanted to share this with you: I made a major mode for
> the tool fpscalc. fpscalc (fps = fixed priority
There's gnu.emacs.sources specifically for these kinds of announcements.
> serious people, so I would be very appreciative if you
> gave me feedback.
See below,
Stefan
> ;;;; fpscalc-mode
Try C-u M-x checkdoc-current-buffer RET. It'll help you follow some of
the usual conventions.
> (defface fpscalc-program-parts-face
> '((t :background "black" :foreground "magenta" :bold t))
> "The words declarations, initialise, semaphores, and formulas."
> :group 'fpscalc-faces)
You can remove the "-face" suffix.
You need to (defgroup 'fpscalc-faces ...) first.
After that, you can remove the ":group 'fpscalc-faces".
> (defvar fpscalc-program-parts-face 'fpscalc-program-parts-face)
Please throw this away. It just helps to confuse people.
> (defface fpscalc-comment-face
> '((t :background "black" :foreground "blue" :bold t))
> "The comment sign (!) as well as everything to its right."
> :group 'fpscalc-faces)
I can live with new faces for some perceived customizability need, but
don't ignore the user's pre-existing preferences. I.e. make your faces
inherit from the corresponding font-lock face, so that users can
customize their faces specifically for your mode, but they don't have to.
> (add-to-list 'auto-mode-alist '("\\.fps\\'" . fpscalc-mode))
Good. You probably want to add a ";;;###autoload" cookie in front, in
case you want to distribute your file via ELPA, for example.
> (setq fpscalc-keywords
`setq' is for modifying the value of a previously declare variable.
Use `defvar' here, please.
> (define-derived-mode fpscalc-mode c-mode
> "fpscalc-mode is a major mode for the tool fpscalc."
The third arg of define-derived-mode is not the docstring but the mode's name.
> (setq mode-name "fpscalc")
Once you fix the previous problem, you can get rid of this.
> (set-variable 'line-number-mode t t)
Why? It's enabled by default anyway, and I can't think of any reason
why fpscalc-mode would need to enable it even if the user decided to
disable it globally.
Oh, and don't call `set-variable' from Elisp. It's a command meant for M-x.
> (abbrev-mode 0) ; disable (gets it from the C mode)
Why should you disable it? I think what you want to do here instead is
to get rid of c-mode's abbreviations (i.e. setup fpscalc-mode's own
abbrev-table).
> :syntax-table fpscalc-syntax-table
This has no effect, because it would only have an effect if it were
right after the docstring. In any case, the right way to do it is to
name your syntax-table `fpscalc-mode-syntax-table' and to place its
definition before define-derived-mode.
> (define-key fpscalc-mode-map [remap comment-dwim] 'fpscalc-comment-dwim)
Same for fpscalc-mode-map: define it once and for all before the
define-derived-mode.
> (defun fpscalc-comment-dwim (cmt)
> (interactive "*P")
> (require 'newcomment)
> (let ((comment-start "!") (comment-end ""))
> (comment-dwim cmt) ))
Don't do that. Just do
(set (make-local-variable 'comment-start) "!")
(set (make-local-variable 'comment-end) "")
in fpscalc-mode.
> (defvar fpscalc-syntax-table nil "The syntax table for `fpscalc-mode'.")
> (setq fpscalc-syntax-table
> (let ((syntax-table (make-syntax-table)))
> (modify-syntax-entry ?! "< b" syntax-table)
> (modify-syntax-entry ?\n "> b" syntax-table)
> syntax-table) )
Merge the two:
(defvar fpscalc-mode-syntax-table
(let ((syntax-table (make-syntax-table)))
(modify-syntax-entry ?! "< b" syntax-table)
(modify-syntax-entry ?\n "> b" syntax-table)
syntax-table)
"The syntax table for `fpscalc-mode'.")
> (defconst *path-of-fpscalc* "/home/incal/dvk/rt/fpscalc/fpscalc")
That should probably be turned into
(defcustom fpscalc-command-name "fpscalc"
"Name of the `fpscalc' executable to use."
:type 'file)
> (defun compute ()
> (interactive)
> (let*((src (buffer-file-name))
> (dst (format "%s_fallout.txt" src)))
> (shell-command (format "%s < %s > %s" *path-of-fpscalc* src dst))
If `src' includes funny characters (like semi-colons, dollars, ...),
this will not do what you intended: you should pass `src' and `dst'
through shell-quote-argument.
> (find-file dst) ))
You might prefer (display-buffer (find-file-noselect dst)), so that it
doesn't always replace the source buffer, but can display the output in
another window.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.2705.1379874790.10748.help-gnu-emacs@gnu.org>]
* Re: major mode for fpscalc + some meta
[not found] ` <mailman.2705.1379874790.10748.help-gnu-emacs@gnu.org>
@ 2013-09-22 23:20 ` Emanuel Berg
2013-09-23 0:15 ` Stefan Monnier
[not found] ` <mailman.2719.1379895349.10748.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-09-22 23:20 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> There's gnu.emacs.sources specifically for these kinds
> of announcements.
No, I think this was the perfect place to post :)
> See below,
*Thanks a zillion*! This is *exactly* the way to do it!
Here is the new source:
http://user.it.uu.se/~embe8573/fps/fpscalc.el
and a dump:
http://user.it.uu.se/~embe8573/fps/fpscalc.bmp
and a readme:
http://user.it.uu.se/~embe8573/fps/readme.txt
This was the most amazing thing since "Jurassic Park"!
(But if you see something else, tell me, of course.)
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: major mode for fpscalc + some meta
2013-09-22 23:20 ` Emanuel Berg
@ 2013-09-23 0:15 ` Stefan Monnier
[not found] ` <mailman.2719.1379895349.10748.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2013-09-23 0:15 UTC (permalink / raw)
To: help-gnu-emacs
> (But if you see something else, tell me, of course.)
define-abbrev-table should be at the top-level, not within fpscalc-mode.
You mis-copied my code:
(display-buffer (find-file-noselect dst))
not
(display-buffer (find-file dst))
and of course, this won't work any more when src and dst include
funny characters: you want to pass to `find-file(-noselect)' the
non-quoted file.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.2719.1379895349.10748.help-gnu-emacs@gnu.org>]
* Re: major mode for fpscalc + some meta
[not found] ` <mailman.2719.1379895349.10748.help-gnu-emacs@gnu.org>
@ 2013-09-23 1:11 ` Emanuel Berg
2013-09-23 3:08 ` Stefan Monnier
[not found] ` <mailman.2723.1379905744.10748.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-09-23 1:11 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> define-abbrev-table should be at the top-level, not
> within fpscalc-mode.
>
> and of course, this won't work any more when src and
> dst include funny characters: you want to pass to
> `find-file(-noselect)' the non-quoted file.
I updated the source:
http://user.it.uu.se/~embe8573/fps/fpscalc.el
Now it looks like this:
(defun compute ()
"Run the system defined in the current buffer (i.e.,
an .fps file), save the fallout in a file, and show that
file in a new buffer."
(interactive)
(let*((src (buffer-file-name))
(dst (format "%s_fallout.txt" src))
(srcq (shell-quote-argument src))
(dstq (shell-quote-argument dst)) )
(shell-command
(format "%s < %s > %s" fpscalc-command-name srcq dstq))
(display-buffer (find-file-noselect dst)) ))
(add-hook 'fpscalc-mode-hook 'init-fpscalc-abbrevs)
(defun init-fpscalc-abbrevs ()
(define-abbrev-table 'fpscalc-mode-abbrev-table
'(("init" "initialise")
("prio" "priority") )))
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: major mode for fpscalc + some meta
2013-09-23 1:11 ` Emanuel Berg
@ 2013-09-23 3:08 ` Stefan Monnier
[not found] ` <mailman.2723.1379905744.10748.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2013-09-23 3:08 UTC (permalink / raw)
To: help-gnu-emacs
> (add-hook 'fpscalc-mode-hook 'init-fpscalc-abbrevs)
> (defun init-fpscalc-abbrevs ()
> (define-abbrev-table 'fpscalc-mode-abbrev-table
> '(("init" "initialise")
> ("prio" "priority") )))
Why don't you want to put define-abbrev-table needs at top-level as just
the code below, somewhere before the define-derived-mode definition?
(define-abbrev-table 'fpscalc-mode-abbrev-table
'(("init" "initialise")
("prio" "priority") ))
-- Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.2723.1379905744.10748.help-gnu-emacs@gnu.org>]
* Re: major mode for fpscalc + some meta
[not found] ` <mailman.2723.1379905744.10748.help-gnu-emacs@gnu.org>
@ 2013-09-23 3:23 ` Emanuel Berg
2013-09-23 3:25 ` Emanuel Berg
2013-10-02 0:19 ` Emanuel Berg
1 sibling, 1 reply; 15+ messages in thread
From: Emanuel Berg @ 2013-09-23 3:23 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> Why don't you want to put define-abbrev-table needs at
> top-level as just the code below, somewhere before the
> define-derived-mode definition?
>
> (define-abbrev-table 'fpscalc-mode-abbrev-table
> '(("init" "initialise")
> ("prio" "priority") ))
Because that doesn't work.
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: major mode for fpscalc + some meta
[not found] ` <mailman.2723.1379905744.10748.help-gnu-emacs@gnu.org>
2013-09-23 3:23 ` Emanuel Berg
@ 2013-10-02 0:19 ` Emanuel Berg
2013-10-02 0:58 ` Stefan Monnier
[not found] ` <mailman.3228.1380675623.10748.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 15+ messages in thread
From: Emanuel Berg @ 2013-10-02 0:19 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2013-10-02 4:07 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-22 14:45 major mode for fpscalc + some meta Emanuel Berg
2013-09-22 18:32 ` Stefan Monnier
2013-09-22 23:07 ` Suvayu Ali
[not found] ` <mailman.2705.1379874790.10748.help-gnu-emacs@gnu.org>
2013-09-22 23:20 ` Emanuel Berg
2013-09-23 0:15 ` Stefan Monnier
[not found] ` <mailman.2719.1379895349.10748.help-gnu-emacs@gnu.org>
2013-09-23 1:11 ` Emanuel Berg
2013-09-23 3:08 ` Stefan Monnier
[not found] ` <mailman.2723.1379905744.10748.help-gnu-emacs@gnu.org>
2013-09-23 3:23 ` Emanuel Berg
2013-09-23 3:25 ` Emanuel Berg
2013-10-02 0:19 ` Emanuel Berg
2013-10-02 0:58 ` Stefan Monnier
[not found] ` <mailman.3228.1380675623.10748.help-gnu-emacs@gnu.org>
2013-10-02 1:05 ` Emanuel Berg
2013-10-02 2:05 ` Stefan Monnier
[not found] ` <mailman.3233.1380679539.10748.help-gnu-emacs@gnu.org>
2013-10-02 2:10 ` Emanuel Berg
2013-10-02 4:07 ` Eli Zaretskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).