filters.el 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ;;; srecode/filters.el --- Filters for use in template variables.
  2. ;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <eric@siege-engine.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; Various useful srecoder template functions.
  18. ;;; Code:
  19. (require 'newcomment)
  20. (declare-function srecode-dictionary-lookup-name "srecode/dictionary")
  21. (defvar srecode-inserter-variable-current-dictionary)
  22. (defun srecode-comment-prefix (str)
  23. "Prefix each line of STR with the comment prefix characters."
  24. (let* ((dict srecode-inserter-variable-current-dictionary)
  25. ;; Derive the comment characters to put in front of each line.
  26. (cs (or (and dict
  27. (srecode-dictionary-lookup-name dict "comment_prefix"))
  28. (and comment-multi-line comment-continue)
  29. (and (not comment-multi-line) comment-start)))
  30. (strs (split-string str "\n"))
  31. (newstr "")
  32. )
  33. (while strs
  34. (cond ((and (not comment-multi-line) (string= (car strs) ""))
  35. ; (setq newstr (concat newstr "\n")))
  36. )
  37. (t
  38. (setq newstr (concat newstr cs " " (car strs)))))
  39. (setq strs (cdr strs))
  40. (when strs (setq newstr (concat newstr "\n"))))
  41. newstr))
  42. (provide 'srecode/filters)
  43. ;;; srecode/filters.el ends here