emacs

General discussion about Elmer
Post Reply
Carlos Martin
Posts: 1
Joined: 24 Sep 2009, 14:47

emacs

Post by Carlos Martin »

Elmeristas,

After years editing Elmer sif files with Emacs, I have realized today how easy is to create an Emacs mode for sif files and put a bit of colour in them.

This is my first attempt, essentially a copy and paste from the emacs generic mode tutorial in http://www.emacswiki.org/emacs/GenericMode . The following code have to be added to the ".emacs" file.

Code: Select all

(require 'generic-x)

(define-generic-mode 
      'sif-mode                         ;; name of the mode to create
      '("!" "#")                           ;; comments start with '!' or "#'
      '("Header" "Constants" "Material" "End" "Solver" "Boundary Condition"
        "Simulation" "Body" "Body Force" "Initial Condition" "Equation")                     ;; some keywords
     '(("=" . 'font-lock-operator)  ;; This doesn't do anything!
        ("$$" . 'font-lock-builtin)   ;; or this!
	("Real" "Logical" "String" "Integer" . 'font-lock-type-face))     ;; or this! 
      '("\\.sif$")                      ;; files for which to activate this mode 
       nil                              ;; other functions to call
      "A mode for sif files"            ;; doc string for this mode
)
It doesn't work perfectly but comments, keywords and MATC expresions look great.

I am just wondering if anyone has been working on this and doesn't mind to share it. Comments welcomed!
raback
Site Admin
Posts: 4828
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: emacs

Post by raback »

Hi Carlos

Nice work! I'll certainly give it a try. The idea has been there before but I don't know that anybody would have actually implemented it before.

-Peter
fgillet
Posts: 47
Joined: 30 Sep 2010, 16:58

Re: emacs

Post by fgillet »

Thanks for the tip Carlos.
As I'm a vi fan I did a quick syntax file for vi.

to put under ~/.vim/syntax/sif.vim

Code: Select all


if version < 600
        syn clear
elseif exists("b:current_syntax")
        finish
endif

syn case    ignore


syn keyword SifType Real Integer Logical String File Procedure MATC

syn match  SifNumber            display "[+-]\=\<\d\+\>"
syn match  SifFloat           "\<\d\+\(\.\d*\)\=\([edED][-+]\=\d\+\)\=[ij]\=\>"
syn match  SifFloat           "\.\d\+\([edED][-+]\=\d\+\)\=[ij]\=\>"
syn region  SifString         start=+"+ end=+"+ oneline


syn match SifComment "!.*"

syn region SifSolvers start="Linear" end="="
syn region SifSolvers start="nonlinear" end="="

syn match SifSolverHeader "Exec\s*Solver\s*="
syn match SifSolverHeader "Variable\s*="
syn match SifSolverHeader "Variable\s*Dofs\s*="
syn match SifSolverHeader "Equation\s*="
syn match SifSolverHeader "procedure\s*="

syn match SiftargetBC "Target\s*Boundaries\s*="

syntax match MatcFunction "\$\sfunction"

syn keyword SifUnit Simulation Header End
syn match  SifUnit "Body\s*\d\+"
syn match  SifUnit "Material\s*\d\+"
syn match  SifUnit "Solver\s*\d\+"
syn match  SifUnit "Equation\s*\d\+"
syn match  SifUnit "Initial\s*Condition\s*\d\+"
syn match  SifUnit "Body\s*Force\s*\d\+"
syn match  SifUnit "Boundary\s*Condition\s*\d\+"


hi def SifBold cterm=bold

if version >= 508 || !exists("did_sif_syntax_inits")
        if version < 508
                let did_sif_syntax_inits = 1
                command -nargs=+ HiLink hi link <args>
        else
                command -nargs=+ HiLink hi def link <args>
        endif

   HiLink SifNumber          Number
   HiLink SifFloat           Float
   HiLink SifString          String
   HiLink SifComment         Comment
   HiLink SifUnit            Special
   HiLink SifSolvers         Keyword
   HiLink SifSolverHeader    SifBold
   HiLink MatcFunction       SifBold
   HiLink SiftargetBC        SifBold
   HiLink SifType            Type

   delcommand HiLink
endif

let b:current_syntax = "sif"

and add this under ~/.vim/filetype.vim

Code: Select all

augroup filetypedetect
au BufNewFile,BufRead *.sif setf sif
augroup END
sure it can be improved but it already gives nice colors.

Best
Fabien
kglub
Posts: 2
Joined: 09 Jul 2010, 11:39

Re: emacs

Post by kglub »

And thanks for your vim code Fabien!

Miguel
hazelsct
Posts: 153
Joined: 05 Oct 2009, 17:02
Location: Boston, MA, USA
Contact:

Re: emacs

Post by hazelsct »

Another thanks Carlos, I like it!
Sleeper
Posts: 1
Joined: 02 Nov 2011, 10:38
Antispam: Yes

Re: emacs

Post by Sleeper »

That's really amazing code! How long did it take you to develop it?
Takala
Posts: 186
Joined: 23 Aug 2009, 23:59

Vim: ElmerFEM Solver Input File Syntax highlighting

Post by Takala »

Hello Elmer users,

I have set up a repository for vim-elmer plugin.

It has some nice features:
- syntax highlighting
- code folding
- Custom Elmer installation Keyword fetching (ELMER_HOME environment variable needs to be set)

See the attached image
Attachments
vim-elmer.jpg
(267.09 KiB) Not downloaded yet
Post Reply