OSDN Git Service

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