Preamble
Using the VTK library with C ++, I often write something like this:
vtkInteractorStyleRubberBandZoom *isrbz = vtkInteractorStyleRubberBandZoom::New();
In addition, every time I need to use a new VTK class in my program, I have to go somewhere up the source file and add #include "vtkInteractorStyleRubberBandZoom.h"
How can I automate it, so I have to type each of the painfully long class names once instead of three?
I tried recording Little Emacs mode for him. There are probably already existing solutions (YaSnippet?), But I thought that writing myself would also be a good exercise.
the code
;vtk-mode.el
;add to .emacs:
;(load "vtk-mode")
;(global-set-key [(control =)] 'expand-vtk)
(defun expand-vtk ()
(interactive)
(setq now (point))
(setq vtkstart (search-backward "vtk"))
(setq vtkend (- (search-forward " ") 1))
(setq vtkname (buffer-substring vtkstart vtkend))
;check for
(setq includename (format "#include \"%s.h\"\n" vtkname))
(search-backward includename nil (append-include-vtk includename))
(goto-char (+ now (length includename)))
(insert (format "= %s::New();" vtkname)))
(defun append-include-vtk (incname)
(goto-char 0)
(insert incname))
Problem
Basically, it works, except that finding the name include always fails, e. g :.
vtkSomething *smth
vtkSomething *smth = vtkSomething::New();
vtkSomething *smth2
What am I doing wrong here with looking back?
( ( ) , (length includename), , , , )