123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- (defun mantemp-remove-comments ()
- "Remove g++ comments surrounding each function and member function."
- (save-excursion
- (goto-char (point-min))
- (message "Removing comments")
- (while (re-search-forward "^[A-z\.()+0-9: ]*`\\|'.*$" nil t)
- (replace-match ""))))
- (defun mantemp-remove-memfuncs ()
- "Remove member function extensions so that only class names remain."
- (save-excursion
-
- (goto-char (point-min))
- (message "Removing member function extensions")
- (while (re-search-forward
- "^[A-z :&*<>~=,0-9+]*>::operator " nil t nil)
- (progn
- (backward-char 11)
- (delete-region (point) (line-end-position))))
-
- (goto-char (point-min))
- (message "Removing member function extensions")
- (while (re-search-forward "^[A-z :&*<>~=,0-9+]*>::" nil t nil)
- (progn
- (backward-char 2)
- (delete-region (point) (line-end-position))))))
- (defun mantemp-sort-and-unique-lines ()
- "Eliminate all consecutive duplicate lines in the buffer."
- (save-excursion
- (message "Sorting")
- (sort-regexp-fields nil "^.*$" "\\&"
- (point-min)
- (point-max))
- (goto-char (point-min))
- (message "Removing consecutive duplicate lines")
- (while (re-search-forward "\\(^.+\\)\n\\1" nil t nil)
- (progn
- (forward-line -1)
- (beginning-of-line)
- (delete-region (point) (progn (forward-line 1) (point)))))))
- (defun mantemp-insert-cxx-syntax ()
- "Insert C++ syntax around each template class and function.
- Insert 'template class' for classes, 'template' for
- functions and add the statement delimiter `;' at the end of
- the lines."
- (save-excursion
-
- (goto-char (point-min))
- (message "Inserting `;' at the ends")
- (while (re-search-forward ".+$" nil t)
- (progn
- (insert ";")
- (if (not (equal (point) (point-max)))
- (forward-char))))
-
-
-
- (goto-char (point-min))
- (message "Inserting 'template class' for classes")
- (while (re-search-forward "^.+" nil t)
- (progn
- (beginning-of-line)
- (if (looking-at "struct[\\t ]+\\|class[\\t ]+")
- (insert "template ")
- (insert "template class "))))
- (goto-char (point-min))
- (message "Inserting 'template' for functions")
- (while (re-search-forward
- "^template class [A-z :&*<>~=,0-9+!]*(" nil t nil)
- (progn
- (beginning-of-line)
- (forward-word 1)
- (delete-region (point) (progn (forward-word 1) (point)))))))
- (defun mantemp-make-mantemps ()
- "Gathering interface to the functions modifying the buffer."
- (mantemp-remove-comments)
- (mantemp-remove-memfuncs)
- (mantemp-sort-and-unique-lines)
- (mantemp-insert-cxx-syntax))
- (defun mantemp-make-mantemps-buffer ()
- "Make manual template instantiations from g++ error messages in the buffer.
- Scan the output of g++ describing uninstantiated template
- classes and functions and generate the corresponding C++
- manual template instantiations. The output is supposed to
- have been placed in the current buffer and the current buffer
- should otherwise be empty.
- See the commentary in file mantemp.el for an example of use."
- (interactive)
- (mantemp-make-mantemps)
- (message "Done"))
- (defun mantemp-make-mantemps-region ()
- "Make manual template instantiations from g++ error messages in the region.
- This function does the same thing as `mantemp-make-mantemps-buffer',
- but operates on the region."
- (interactive)
- (let ((cur-buf (current-buffer))
- (mantemp-buffer (generate-new-buffer "*mantemp*"))
- (str (buffer-substring (mark) (point))))
-
-
- (set-buffer mantemp-buffer)
- (insert str)
- (mantemp-make-mantemps)
- (setq str (buffer-string))
- (set-buffer cur-buf)
- (insert str)
- (kill-buffer mantemp-buffer))
- (message "Done"))
- (provide 'mantemp)
|