#令和3年3月31日付告発状 Emacs-Lisp関数# Markdownから見出しレベルを指定しWikiに投稿するデータを生成するEmacs-Lisp関数
〉〉〉 Linux Emacs: 2021/04/14 11:31:41 〉〉〉
;; 2021-04-14 (defun k-markdown-copy-to-subtree-wiki (arg) "Narrow buffer to the current subtree." (interactive "p") (save-excursion (let ((=start)(=end)(=p)(line_start)(line_end)) ;;(markdown-outline-previous) (setq exec (lambda (pattern1 pattern2) (setq =p (point)) (re-search-backward pattern1 nil t)(setq =start (point)) (beginning-of-line)(setq line_start (point)) (end-of-line)(setq line_end (point)) (setq lv1 (concat "./" (car (nthcdr 5 (split-string (buffer-file-name) "/"))) "/")) (setq lv2 (concat (car (nthcdr 6 (split-string (buffer-file-name) "/"))) "/")) (setq title (concat lv1 lv2 (buffer-substring line_start line_end))) ;;(progn (markdown-back-to-heading-over-code-block t) (setq =start (point))) ;;(progn (markdown-end-of-subtree) ;;(if (and (markdown-heading-at-point) (not (eobp))) (goto-char =p)(message (int-to-string =start))(message (format "\\(%s\\|%s\\)" pattern2 pattern1)) (cond ((re-search-forward (format "\\(%s\\|%s\\)" pattern2 pattern1) nil t) (progn (backward-char 1)(beginning-of-line)(setq =end (point)))) (t (message "該当なし")))(message "%s" (int-to-string =end)) (setq fname (file-name-nondirectory (buffer-file-name))) (string-match ".+_\\(.+\\)\\.md" fname) (setq fname (match-string 1 fname)) ;;(copy-region-as-kill =start =end) ;; 指定した範囲のリージョンのテキストを変数に代入 (setq title (replace-regexp-in-string "#+ " "" title)) ;;(setq title (concat fname " #令和3年3月31日付告発状 " title)) (setq fname (concat "TITLE:" title)) (setq fname (concat fname "\n#contents\n----\n")) (setq text (buffer-substring-no-properties =start =end)) (setq text (concat fname text)) (setq text (replace-regexp-in-string "^#### " "**** " text)) (setq text (replace-regexp-in-string "^### " "*** " text)) (setq text (replace-regexp-in-string "^## " "** " text)) (setq text (replace-regexp-in-string "^# " "* " text)) (message title) ;; クリップボードに変数の内容を送る。 (generate-new-buffer "a") (with-temp-buffer (insert text) (call-process-region (point-min) (point-max) "xsel" nil "a" nil "--clipboard" "--input")) (message "%s" (buffer-string)) (kill-buffer "a") (generate-new-buffer "b") (with-temp-buffer (insert title) (call-process-region (point-min) (point-max) "xsel" nil "b" nil "--primary" "--input") (message "%s" (buffer-string))) (kill-buffer "b"))) ;; (if (boundp n) ;; (setq n 3)) (if arg (setq n arg) (setq n 3)) ;;なぜか1の処理が実行される。なかなか消えなかったエラー。 (cond ((eq n 1) (funcall exec "^# .+$" "^# .+$")) ((eq n 2) (funcall exec "^## .+$" "^# .+$")) ((eq n 3) (funcall exec "^### .+$" "^## .+$")) (t (funcall exec "^### .+$" "^## .+$"))) )))