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