yasnippet_function.el 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. ;;; Msm.el --- A state machine generator
  2. ;; This file is not part of GNU Emacs.
  3. ;; Copyright <2018> <Carl Olsen>
  4. ;; Author: Carl Olsen <olsen.carl@gmail.com>
  5. ;; URL: http://cocode.se:8080/calle/YasSnippet
  6. ;; Version: 0.11
  7. ;; Permission is hereby granted, free of charge, to any person
  8. ;; obtaining a copy of this software and associated documentation
  9. ;; files (the "Software"), to deal in the Software without
  10. ;; restriction, including without limitation the rights to use, copy,
  11. ;; modify, merge, publish, distribute, sublicense, and/or sell copies
  12. ;; of the Software, and to permit persons to whom the Software is
  13. ;; furnished to do so, subject to the following conditions:
  14. ;; The above copyright notice and this permission notice shall be
  15. ;; included in all copies or substantial portions of the Software.
  16. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  20. ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21. ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. ;; SOFTWARE.
  24. ;; This file is part of CoCode software Yassnippet
  25. ;;
  26. ;;; Commentary:
  27. ;; The El-Msm is code generation for Meta state machine
  28. ;; See
  29. ;; https://www.boost.org/doc/libs/1_62_0/libs/msm/doc/HTML/index.html
  30. ;; For more information.
  31. ;;; Code:
  32. ;; Use col/msm-implement-action
  33. (defgroup el-msm nil
  34. "Group for el-msm"
  35. :prefix "msm-"
  36. :group 'tools
  37. :link '(url-link :tag "Website" "http://cocode.se:8080/calle/YasSnippet")
  38. )
  39. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  40. ;; Constants
  41. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  42. (defconst el-msm-package-version "0.11")
  43. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  44. ;; Variables
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46. (defcustom el-msm-event-buffer "events"
  47. "The output buffer name for events."
  48. :group 'el-msm
  49. )
  50. (defcustom el-msm-guard-and-action-buffer "guards_and_actions"
  51. "Output buffer for guards and action structs for Meta state machine."
  52. :group 'el-msm
  53. )
  54. (defcustom el-msm-state-buffer "states"
  55. "Output buffer for guards and action structs for Meta state machine."
  56. :group 'el-msm
  57. )
  58. (defvar el-msm-statechart-name nil)
  59. (cl-defstruct MsmRow Src Dest Ev Action Guard Refs )
  60. ;;##############################
  61. ;;Interactive functions
  62. ;;##############################
  63. (defun col/msm-implement-events()
  64. "Implements events structs"
  65. (interactive)
  66. (let (msmRow outBuff stName)
  67. (setq outBuff (col/msm-create-output-buffer-name (buffer-name) el-msm-event-buffer))
  68. (setq stName (col/msm-get-statechart-name))
  69. (setq msmRow (col/find-all-actions stName))
  70. (col/create-uml-statemachine msmRow)
  71. (col/find-all-references msmRow)
  72. (switch-to-buffer outBuff)
  73. (col/create-event-implement msmRow)
  74. (previous-buffer)
  75. (switch-to-buffer-other-window outBuff)
  76. (c++-mode)
  77. (indent-region (point-min) (point-max))
  78. ;;(popup-menu* '("Foo" "Bar" "Baz"))
  79. )
  80. )
  81. (defun col/msm-implement-action()
  82. " Reads the Statemachine and finds all the actions, and creates a skeleton"
  83. (interactive)
  84. (let (msmRow outputBuffer statechart-name)
  85. (setq outputBuffer (col/msm-create-output-buffer-name (buffer-name) el-msm-guard-and-action-buffer))
  86. (setq statechart-name (col/msm-get-statechart-name))
  87. (setq msmRow (col/find-all-actions statechart-name))
  88. (switch-to-buffer outputBuffer)
  89. (col/create-action-implement msmRow )
  90. (previous-buffer)
  91. (switch-to-buffer-other-window outputBuffer)
  92. (c++-mode)
  93. (indent-region (point-min) (point-max))
  94. )
  95. )
  96. ;TODO: Work in progress
  97. (defun col/msm-implement-states()
  98. "Read statemachine states and add creates buffer with states"
  99. (interactive)
  100. (let (msmRow stateBuffer statechart-name)
  101. (setq stateBuffer (col/msm-create-output-buffer-name (buffer-name) el-msm-state-buffer))
  102. (setq statechart-name (col/msm-get-statechart-name))
  103. (setq msmRow (col/find-all-actions statechart-name)) ;This should contain the information needed.
  104. (switch-to-buffer stateBuffer)
  105. (col/create-state-implement msmRow)
  106. (previous-buffer)
  107. (switch-to-buffer-other-window stateBuffer)
  108. (c++-mode)
  109. (indent-region (point-min) (point-max))
  110. )
  111. )
  112. ;; Is not finished?!?
  113. (defun col/find-all-references( msmRow )
  114. "Find all references will take the events
  115. and iterate throough the list. for every
  116. time it finds the "
  117. (dolist (row msmRow)
  118. (dolist (row1 msmRow)
  119. (if (and
  120. (not (eq row row1))
  121. (string= (MsmRow-Ev row1) (MsmRow-Ev row))
  122. )
  123. (progn
  124. ;;Found an event that is the same but something is differnt.
  125. ;; So lets store that as a reference.
  126. (setf (MsmRow-Refs row) (cons (MsmRow-Refs row) row1))
  127. )
  128. )
  129. )
  130. )
  131. msmRow
  132. )
  133. ;;##############################
  134. (defun col/create-event-implement( msmRowList )
  135. "Inserts the event structure in current buffer"
  136. (save-excursion
  137. (dolist (row msmRowList)
  138. (if (and
  139. (not (string-match "none" (MsmRow-Ev row)) )
  140. (not (col/check-struct-existence (MsmRow-Ev row)))
  141. )
  142. (progn
  143. (insert (col/msm-create-event-comment row))
  144. (insert (col/msm-create-event-struct row))
  145. )
  146. )
  147. )
  148. )
  149. )
  150. (defun col/create-action-implement( msmRowList )
  151. "inserts the action at the current position"
  152. (save-excursion
  153. (dolist (row msmRowList)
  154. (if (and
  155. (not (string-match "none" (MsmRow-Guard row)) )
  156. (not (col/check-struct-existence (MsmRow-Guard row)))
  157. )
  158. (progn
  159. (insert (col/msm-make-guard-comment row))
  160. (insert (col/msm-create-guard-struct row))
  161. )
  162. )
  163. (if (and
  164. (not (string-match "none" (MsmRow-Action row)))
  165. (not (col/check-struct-existence (MsmRow-Action row)))
  166. )
  167. (progn
  168. (insert (col/msm-make-action-comment row))
  169. (insert (col/msm-create-action-struct row))
  170. )
  171. )
  172. )
  173. )
  174. )
  175. (defun col/create-state-implement( msmRowList )
  176. "Insert the state into the current buffer"
  177. (save-excursion
  178. (dolist (row msmRowList)
  179. (if (not
  180. (col/check-struct-existence (MsmRow-Src row) )
  181. )
  182. (progn
  183. (insert (col/msm-make-state-comment (MsmRow-Src row)))
  184. (insert (col/msm-create-state-struct (MsmRow-Src row)))
  185. )
  186. )
  187. (if (not
  188. (col/check-struct-existence (MsmRow-Dest row) )
  189. )
  190. (progn
  191. (insert (col/msm-make-state-comment (MsmRow-Dest row)))
  192. (insert (col/msm-create-state-struct (MsmRow-Dest row)))
  193. )
  194. )
  195. )
  196. )
  197. )
  198. (defun col/msm-get-statechart-name()
  199. "get the statechart name from the alias declaration"
  200. (save-excursion
  201. (if (or (re-search-forward "^typedef\s+.*::back::state_machine<.*>\s+\\(.*\\);" nil t)
  202. (re-search-forward "^using\s+\\(.*?\\)\s*=\s*.*::back::state_machine<.*>\s*;" nil t))
  203. (match-string-no-properties 1)
  204. )
  205. )
  206. )
  207. ;;##############################
  208. ;; Create output
  209. ;;##############################
  210. (defun col/msm-make-state-comment( stateName )
  211. "Makes comment for states"
  212. (format "\
  213. /**\n\
  214. * \\class %s\n\
  215. * \\brief purpose of %s is ....\n\
  216. *\n\
  217. * on_entry:\n\
  218. * on_exit:\n\
  219. */\n"
  220. stateName
  221. stateName
  222. )
  223. )
  224. ;; * \\class %s\n\
  225. ;; * \\brief purpose of %s is ....\n\
  226. ;; *\n\
  227. ;; * on_entry:\n\
  228. ;; * on_exit:\n\
  229. ;; *\/\n\" (MsmRow-src row)
  230. (defun col/msm-create-event-comment( row )
  231. "Creates a comment for event class"
  232. (format "\
  233. /**\n\
  234. * \\class %s\n\
  235. * \\brief short description about the event\n\
  236. *\n\
  237. * a longer description\n\
  238. * This event completes the transition between: %s -> %s\n\
  239. * Action during this transition %s\n\
  240. * @see %s source\n\
  241. * @see %s destination\n\
  242. * @see %s action\n\
  243. */\n"
  244. (MsmRow-Ev row)
  245. (MsmRow-Src row)
  246. (MsmRow-Dest row)
  247. (MsmRow-Action row)
  248. (MsmRow-Src row)
  249. (MsmRow-Dest row)
  250. (MsmRow-Action row)
  251. )
  252. )
  253. (defun col/msm-create-event-struct( row )
  254. "Creates a new event class"
  255. (format "\
  256. class %s \n\
  257. {\n\
  258. public:\n\
  259. %s(){}\n\
  260. ~%s(){}\n\
  261. };\n\n"
  262. (MsmRow-Ev row)
  263. (MsmRow-Ev row)
  264. (MsmRow-Ev row)
  265. )
  266. )
  267. (defun col/msm-create-state-struct( stateName )
  268. "Create a formatted string with the states."
  269. (format "\
  270. class %s : public msmf::state<> { \n\
  271. public:\n\
  272. \n\
  273. template <class Event,class Fsm>\n\
  274. void on_entry(const Event& , Fsm&) const {\n\
  275. \n\
  276. }\n\
  277. \n\
  278. \n\
  279. template <class Event,class Fsm>\n\
  280. void on_exit(const Event&, Fsm& fsm) const {\n\
  281. \n\
  282. }\n\
  283. }; // End of state %s\n\n"
  284. stateName
  285. stateName
  286. )
  287. )
  288. (defun col/msm-create-action-struct( row )
  289. "Create a formatted string for the struct"
  290. (format "struct %s {\n\
  291. template <class Event, class Fsm, class SourceState, class TargetState>\n\
  292. void operator()(Event const&, Fsm&, SourceState&, TargetState&) const\n\
  293. {\n}\n};\n\n"
  294. (MsmRow-Action row)
  295. )
  296. )
  297. (defun col/msm-create-guard-struct( row )
  298. "Create a formatted string for the guard-struct"
  299. (format "struct %s {\n\
  300. template <class Event, class Fsm, class SourceState, class TargetState>\n\
  301. bool operator()(Event const&, Fsm&, SourceState&, TargetState&) const\n\
  302. {\n}\n};\n\n"
  303. (MsmRow-Guard row)
  304. )
  305. )
  306. (defun col/msm-make-action-comment( row )
  307. "Creates a comment for every Action"
  308. (format "\
  309. /**\n\
  310. * \\class %s\n\
  311. * \\brief short description about the Action\n\
  312. *\n\
  313. * a longer description\n\
  314. * This action happens between %s -> %s\n\
  315. * When event %s occurs\n\
  316. * @see %s source \n\
  317. * @see %s dest \n\
  318. * @see %s occurs\n\
  319. */\n"
  320. (MsmRow-Action row)
  321. (MsmRow-Src row)
  322. (MsmRow-Dest row)
  323. (MsmRow-Ev row)
  324. (MsmRow-Src row)
  325. (MsmRow-Dest row)
  326. (MsmRow-Ev row)
  327. )
  328. )
  329. (defun col/msm-make-guard-comment( row )
  330. "Create a comment for every Guard"
  331. (format "\
  332. /**\n\
  333. * \\class %s\n\
  334. * \\brief short description about the guard\n\
  335. *\n\
  336. * a longer description\n\
  337. * Guard between (Source-Dest) %s -> %s\n\
  338. * using event %s\n\
  339. * @see %s Source\n\
  340. * @see %s Destination\n\
  341. * @see %s Event\n\
  342. * \\return bool - true if the guard is met\n\
  343. */\n"
  344. (MsmRow-Guard row)
  345. (MsmRow-Src row)
  346. (MsmRow-Dest row)
  347. (MsmRow-Ev row)
  348. (MsmRow-Src row)
  349. (MsmRow-Dest row)
  350. (MsmRow-Ev row)
  351. )
  352. )
  353. ;;##############################
  354. (defun col/check-struct-existence( name )
  355. "Returns nil if not exists "
  356. (save-excursion
  357. (beginning-of-buffer)
  358. (re-search-forward (concat "\\(class\\|struct\\)\s+" name) nil t)
  359. )
  360. )
  361. (defun col/find-all-actions( name )
  362. "Create a list with all the action name"
  363. (let ( transStart transEnd rowList row fieldName src dest)
  364. ;;(beginning-of-buffer)
  365. (goto-char (point-min))
  366. (setq transStart (re-search-forward "\s*\\(class\\|struct\\)\s+\\([a-zA-Z_]+\\)\s*:\s*public\s+\\(mpl\\|boost::mpl\\)::vector" nil t))
  367. (setq transEnd (re-search-forward "};" nil t))
  368. (narrow-to-region transStart transEnd )
  369. ;; (beginning-of-buffer)
  370. (goto-char (point-min))
  371. ;;Now lets search for rows
  372. (setq fieldName "\\([a-zA-Z1-9_:]+\\)")
  373. ;; src
  374. (while (re-search-forward (concat ".*::Row\s*<" fieldName "\s*,"
  375. ;;Ev
  376. fieldName "\s*,"
  377. ;;Dest
  378. fieldName "\s*,"
  379. ;;Action
  380. fieldName "\s*,"
  381. ;;Guard
  382. fieldName "\s*>") nil t)
  383. (setq src (format "%s" (match-string-no-properties 1)))
  384. (setq dest (format "%s" (match-string-no-properties 3)))
  385. (setq row (make-MsmRow :Src src
  386. :Ev (match-string-no-properties 2)
  387. :Dest dest
  388. :Action (match-string-no-properties 4)
  389. :Guard (match-string-no-properties 5)
  390. :Refs ()
  391. ))
  392. ;; (switch-to-buffer "*test*")
  393. ;; (insert (format "%s %s %s %s %s \n"
  394. ;; (MsmRow-Src row)
  395. ;; (MsmRow-Event row)
  396. ;; (MsmRow-Dest row)
  397. ;; (MsmRow-Action row)
  398. ;; (MsmRow-Guard row)
  399. ;; ))
  400. ;; (switch-to-prev-buffer)
  401. (setq rowList (cons row rowList))
  402. )
  403. (widen)
  404. rowList
  405. )
  406. )
  407. (defun col/msm-create-output-buffer-name( name postfix )
  408. "Creates a new buffer name for that corresponds to the statemachine"
  409. (let (fileName)
  410. (setq fileName (file-name-sans-extension name))
  411. (format "%s_%s.hpp" fileName postfix )
  412. )
  413. )
  414. ;;##########
  415. ;; This part will take a MsmRow list
  416. ;; and find the right spot to insert a UML
  417. ;; diagram as good as possible.
  418. ;; It will search for \startuml and
  419. ;; It will search for
  420. ;; insert below.
  421. ;; Therefor its crucial that \startuml and \enduml are
  422. ;; Therefor its crucial that
  423. ;; inserted where the statemachine is to be inserted.
  424. ;;
  425. ;; TODO: Check that the state isn't includede alredy
  426. ;; and that the states transistions are right..
  427. ;; To much work..
  428. ;;##########
  429. ;;ContextView is representing a context for which we narrow a region
  430. (cl-defstruct ContextView StartPos EndPos LineStart)
  431. (defun col/create-uml-statemachine (msmRowList)
  432. "The above documention should be enough"
  433. (save-excursion
  434. (beginning-of-buffer)
  435. (let (lineStart stateMachine begRegEx view viewCom)
  436. (setq stateMachine (col/msm-get-statechart-name))
  437. (setq begRegEx (concat "\\(.*\\)\\\\startuml\s*\"" stateMachine "\".*"))
  438. (setq endRegEx "\\(.*\\)\\\\enduml\s*.*")
  439. (setq view (col/get-context-view "\\(.*\\)\\\\startuml\s*.*" "\\(.*\\)\\\\enduml\s*.*"))
  440. (when (ContextView-p view)
  441. (narrow-to-region (ContextView-StartPos view) (ContextView-EndPos view))
  442. (setq viewCom (col/create-uml-composite-machine
  443. stateMachine
  444. (ContextView-LineStart view)))
  445. (narrow-to-region (ContextView-StartPos viewCom) (ContextView-EndPos viewCom))
  446. (col/create-uml-states msmRowList (ContextView-LineStart view))
  447. (col/create-uml-transitions msmRowList (ContextView-LineStart view))
  448. (widen)
  449. )
  450. )
  451. )
  452. )
  453. (defun col/get-context-view ( startReg endReg )
  454. "Search for a context end and start, and set the positions"
  455. (save-excursion
  456. (beginning-of-buffer)
  457. (let (begPos endPos view lineStart)
  458. (re-search-forward startReg nil t)
  459. (setq lineStart (match-string-no-properties 1))
  460. (insert "\n")
  461. (forward-line 1)
  462. (setq begPos (point))
  463. (re-search-forward endReg nil t)
  464. (forward-line -1)
  465. (setq endPos (point))
  466. ;;(message (format "%s:%d %s:%d" startReg begPos endReg endPos))
  467. (when (and begPos endPos)
  468. (setq view (make-ContextView :StartPos begPos
  469. :EndPos endPos
  470. :LineStart lineStart))
  471. )
  472. ;; view
  473. )
  474. )
  475. )
  476. (defun col/create-uml-transitions (msmRowList lineStart)
  477. "Create transition between states, it it already exists don't"
  478. (let (src dest event transStr regEx)
  479. (dolist (row msmRowList)
  480. (beginning-of-buffer)
  481. ;;TODO: No Guard or action is present in regexp
  482. ;;".*State1\s*[-]+>\s*State2\s*[:]*.*" nil t)
  483. (setq src (col/remove-statemachine-name (MsmRow-Src row)))
  484. (setq dest (col/remove-statemachine-name (MsmRow-Dest row)))
  485. (setq event (col/fix-uml-event row))
  486. (setq regEx (format ".*%s\s*[-]+>\s*%s\s*[:]*.*"
  487. src
  488. dest))
  489. (when (not (re-search-forward regEx nil t))
  490. (end-of-buffer)
  491. (setq transStr (format " %s --> %s %s\n"
  492. src
  493. dest
  494. event))
  495. (insert (concat lineStart transStr))
  496. )
  497. )
  498. ;;(kill-line)
  499. )
  500. )
  501. (defun col/fix-uml-event (row)
  502. "Checks if none exists in that case empty string
  503. is returned"
  504. (let (retStr eventStr guardStr actionStr)
  505. (setq eventStr (col/fix-none-name (MsmRow-Ev row)))
  506. (setq guardStr (col/fix-none-name (MsmRow-Guard row)))
  507. (setq actionStr (col/fix-none-name (MsmRow-Action row)))
  508. (if (and
  509. (not eventStr)
  510. (not guardStr)
  511. (not actionStr))
  512. (setq retStr "")
  513. (progn
  514. (setq retStr ":") ;;Needs to contain a : sign
  515. (when eventStr
  516. (setq retStr (concat retStr " " eventStr))
  517. )
  518. (when guardStr
  519. (setq retStr (concat retStr " [" guardStr "]"))
  520. )
  521. (when actionStr
  522. (setq retStr (concat retStr " / " actionStr))
  523. )
  524. )
  525. )
  526. retStr
  527. )
  528. )
  529. (defun col/fix-none-name (str)
  530. " Fix none to empty string"
  531. (let (strRet)
  532. (if (string-match "none" str)
  533. nil
  534. str
  535. )
  536. )
  537. )
  538. (defun col/create-uml-composite-machine (machine lineStart)
  539. "Create a new composite MACHINE
  540. 1. Check so that it don't exists
  541. 2. add the new statemachine"
  542. (beginning-of-buffer)
  543. (let (view compStart compEnd)
  544. (when (not (re-search-forward (concat "state\s*" machine) nil t))
  545. (insert (concat lineStart "\n"))
  546. (insert (format "%s state %s: on_entry() \\n on_exit()\n" lineStart machine))
  547. (insert (format "%s state %s{\n\n%s}\n"
  548. lineStart
  549. machine
  550. lineStart))
  551. )
  552. (end-of-buffer)
  553. (when (re-search-backward "}" nil t)
  554. (beginning-of-line)
  555. (setq compEnd (point))
  556. (re-search-backward "{" nil t)
  557. (forward-line 1)
  558. (beginning-of-line)
  559. (setq compStart (point))
  560. (setq view (make-ContextView
  561. :StartPos compStart
  562. :EndPos compEnd
  563. :LineStart lineStart))
  564. )
  565. view
  566. )
  567. )
  568. (defun col/create-uml-states ( msmRowList lineStart)
  569. "Use the MSMROWLIST to create a list of string.
  570. Representing the states."
  571. (let (state-str strList name)
  572. (dolist (row msmRowList)
  573. (setq name (col/remove-statemachine-name (MsmRow-Src row)))
  574. (save-excursion
  575. (when (not (re-search-forward (concat "state " name) nil t))
  576. (setq state-str (format "%s state %s\n" lineStart name))
  577. (setq strList (cons strList state-str))
  578. (insert state-str)
  579. )
  580. )
  581. )
  582. ;;Removes the last line..No need for that.
  583. strList
  584. )
  585. )
  586. (defun col/remove-statemachine-name ( stateName )
  587. "removes everything infront of :: "
  588. (let (state)
  589. (if (string-match ".*::\\(.*\\)" stateName)
  590. (progn
  591. (setq state (match-string 1 stateName)))
  592. stateName
  593. )
  594. )
  595. )
  596. ;;##########
  597. ;; These are used for yasnippet
  598. ;;##########
  599. (defun col/format-msm-row( text )
  600. (save-excursion
  601. (let (outputStr)
  602. (setq outputStr (format "%-16s" (col/format-none text)))
  603. )
  604. )
  605. )
  606. (defun col/format-none( text )
  607. (save-excursion
  608. ( if ( string-match "none" text)
  609. "msmf::none"
  610. text)
  611. )
  612. )