snippet-helpers.el 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ;;; javascript
  2. (defun js-method-p ()
  3. (save-excursion
  4. (word-search-backward "function")
  5. (looking-back ": ")))
  6. (defun js-function-declaration-p ()
  7. (save-excursion
  8. (word-search-backward "function")
  9. (looking-back "^\\s *")))
  10. (defun snippet--function-punctuation ()
  11. (if (js-method-p)
  12. (when (not (looking-at "[ \n\t\r]*[},]"))
  13. (insert ","))
  14. (unless (js-function-declaration-p)
  15. (if (looking-at "$") (insert ";")))))
  16. (defun snippet--function-name ()
  17. (if (js-function-declaration-p) "name" ""))
  18. ;; snippet-helper-helpers
  19. (defun chop-suffix (suffix s)
  20. "Remove string 'suffix' if it is at end of string 's'"
  21. (let ((pos (- (length suffix))))
  22. (if (and (>= (length s) (length suffix))
  23. (string= suffix (substring s pos)))
  24. (substring s 0 pos)
  25. s)))
  26. (defun chop-prefix (prefix s)
  27. "Remove string 'prefix' if it is at start of string 's'"
  28. (let ((pos (length prefix)))
  29. (if (and (>= (length s) (length prefix))
  30. (string= prefix (substring s 0 pos)))
  31. (substring s pos)
  32. s)))
  33. (provide 'snippet-helpers)