;;; mag2emacs-transform.el --- るびきち塾メルマガを保存する -*- lexical-binding: t; -*- ;; Copyright (C) 2017 rubikitch ;; Author: rubikitch ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; るびきち塾のメルマガから ;; ヘッダとフッタを取り除いて ;; 特定のディレクトリに保存します。 ;; ;; ファイルは号数とタイトルから構成された ;; orgファイルとなります。 ;; ;; org-seekパッケージを導入することで、 ;; メルマガを保存したディレクトリにて ;; org文書の全文検索が可能になります。 ;; ;; org-seekパッケージについては ;; http://emacs.rubikitch.com/org-seek/ ;; を参照してください。 ;; ;; (require 'mag2emacs-transform) ;; (setq mag2emacs-dir "保存するディレクトリ") ;; ;; の設定を加えてください。 ;; ;; 使い方は3通りあります。 ;; 1. M-x met-output :: カレントバッファを整形して別ウィンドウに表示する ;; 2. M-x mag2emacs-save :: カレントバッファを整形してファイルに保存する ;; 3. M-x dired-mag2emacs-save :: diredでマークしたファイル各々を整形して保存する ;; ;;; Code: (defvar mag2emacs-dir "~/memo/mag2emacs/") (defun met-get-filename () "ファイル名を得る" (save-excursion (goto-char (point-min)) (and (re-search-forward "[0-9p]+号.+$" nil t) (expand-file-name (format "%s.org" (pcase (match-string 0) ("001号』" "001号 画面を彩るテキストプロパティとオーバーレイ") ("002号』" "002号 史上最強!eshellの力を知れ!") ("003号』" "003号 続!史上最強!eshellの力を知れ!") (t (match-string 0)))) mag2emacs-dir)))) (defun dired-mag2emacs-save () "diredでmarkされたメルマガファイルを整形保存する" (interactive) (dolist (f (dired-get-marked-files)) (find-file f) (mag2emacs-save))) (defun mag2emacs-save () "カレントバッファのメルマガファイルを整形保存する" (interactive) (let ((standard-output (find-file-noselect (met-get-filename)))) (with-current-buffer standard-output (erase-buffer)) (met-transform) (switch-to-buffer standard-output) (save-buffer))) (defun met-transform () "冒頭文と本文のみを抜き出して `standard-output' に出力する" (save-excursion (princ "#+TITLE: ") (princ (file-name-base (met-get-filename))) (terpri) ;; 冒頭文 (princ "* 冒頭文\n") (goto-char (point-max)) (search-backward "━━━━━━━━━━━━\n") (forward-line 1) (princ (buffer-substring (point) (progn (search-forward "■■") (forward-line -1) (point)))) (terpri) ;; 本文 (search-forward "■■ 注意事項" nil t) (search-forward "■■ 目次システム" nil t) (re-search-forward "^■■ " nil t) ;; (dotimes (i 2) (re-search-forward "^■■")) (beginning-of-line) (princ (replace-regexp-in-string "^■" "**" (replace-regexp-in-string "^■■" "*" (buffer-substring (point) (progn (or (re-search-forward "\n■■ \\(記事リクエスト・質問について\\|入塾者特典!\\|お願い!\\|お便りください\\|編集後記\\)" nil t) (re-search-forward "^P.S.\n")) ;since #269 (forward-line -1) (point)))))))) (defun met-output () "カレントファイルのメルマガを *mag2emacs* バッファに出力する" (interactive) (let ((temp-buffer-show-hook 'org-mode)) (with-output-to-temp-buffer "*mag2emacs*" (met-transform)))) (provide 'mag2emacs-transform) ;;; mag2emacs-transform.el ends here