Created
February 25, 2013 09:02
-
-
Save serian/5028599 to your computer and use it in GitHub Desktop.
scratchなどで書いた走り書きをリージョン選択してhowmバッファを作成。最後の行が":"で始まってると、それをタイトルにする。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; region2howm.el --- copy a region to howm buffer. | |
;; Copyright (C) 2013 serian | |
;; Author: serian <serian> | |
;; Keywords: tools | |
;; 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 <http://www.gnu.org/licenses/>. | |
;;; Commentary: | |
;; Create howm buffer with a region. | |
;; If the end line of the region starts with ":", this line is copied as title without ":". | |
;; | |
;;; Code: | |
(require 'howm) | |
(defvar region2howm-title-mark ":") | |
(defun region2howm-get-region (start end) | |
(interactive "r") | |
(save-excursion | |
(let* ((title (region2howm-get-title end)) | |
(end-tmp (if (not (string= title "")) (progn (previous-line) (end-of-line) (point)) end)) | |
(buf (buffer-substring-no-properties start end-tmp))) | |
(howm-create-file-with-title title nil nil nil buf)))) | |
(defun region2howm-get-title (end) | |
(goto-char end) | |
(when (bolp) (previous-line)) | |
(beginning-of-line) | |
(if (region2howm-get-title-p (point)) | |
(progn | |
(right-char) | |
(let ((pos1 (point))) | |
(end-of-line) | |
(let ((pos2 (point))) | |
(buffer-substring-no-properties pos1 pos2)))) "")) | |
(defun region2howm-get-title-p (pt) | |
(if (string= (char-to-string (char-after pt)) region2howm-title-mark) t nil)) | |
(provide 'region2howm) | |
;;; region2howm.el ends here | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment