OSDN Git Service

add contributor's name (Yassine-san) into Changelog
[howm/howm.git] / howm-mkmenu.el
1 ;;; howm-mkmenu.el --- Wiki-like note-taking tool
2 ;;; Copyright (C) 2005-2018
3 ;;;   HIRAOKA Kazuyuki <khi@users.osdn.me>
4 ;;; $Id: howm-mkmenu.el,v 1.11 2011-12-31 15:07:29 hira Exp $
5 ;;;
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 1, or (at your option)
9 ;;; any later version.
10 ;;;
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; The GNU General Public License is available by anonymouse ftp from
17 ;;; prep.ai.mit.edu in pub/gnu/COPYING.  Alternately, you can write to
18 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
19 ;;; USA.
20 ;;--------------------------------------------------------------------
21
22 ;; emacs -q --no-site-file -batch -l <this file>
23
24 (defvar howm-mkmenu-rules
25   '(
26     ;; (<var> <src> [<src-coding> <dest-coding>]) ==> <var>.el
27     (howm-menu-en "en/0000-00-00-000000.txt")
28     (howm-menu-fr "fr/0000-00-00-000000.txt" utf-8-unix utf-8-unix)
29     (howm-menu-ja "ja/0000-00-00-000000.txt" euc-jp iso-2022-7bit)
30     ))
31
32 (defmacro howm-mkmenu-insert (&rest clauses)
33   (declare (indent 0))
34   (let ((commands (mapcar (lambda (c)
35                             (let ((format (car c))
36                                   (parameters (cdr c)))
37                               `(insert (format ,(concat format "\n")
38                                                ,@parameters))))
39                           clauses)))
40     `(progn ,@commands)))
41
42 (defun howm-mkmenu (rule)
43   (let ((var (car rule))
44         (src (cadr rule))
45         (opt (cddr rule)))
46     (let ((dest (concat (symbol-name var) ".el"))
47           (src-coding  (and opt (car opt)))
48           (dest-coding (and opt (cadr opt))))
49       ;; read src
50       (when (and src-coding (featurep 'mule))
51         (prefer-coding-system src-coding))
52       (with-temp-buffer
53         (insert-file-contents src)
54         (let ((str (buffer-substring-no-properties (point-min) (point-max))))
55           ;; write to dest
56           (find-file dest)
57           (delete-region (point-min) (point-max))
58           (when dest-coding
59             (set-buffer-file-coding-system dest-coding)
60             (howm-mkmenu-insert
61               (";;; -*- Coding: %s -*-" dest-coding)))
62           (howm-mkmenu-insert
63             (";;; automatically generated from %s" src)
64             (";;; by %s.\n" (file-name-nondirectory load-file-name))
65             ("(require 'howm-vars)\n")
66             ("(howm-defconst-risky %s %S)\n" var str)
67             ("(provide '%s)" var))
68           (let ((make-backup-files nil))
69             (basic-save-buffer))
70           t)))))
71
72 (mapcar #'howm-mkmenu howm-mkmenu-rules)
73
74 ;;; howm-mkmenu.el ends here