(require 'navi2ch) (defun navi2ch-new-thread-check (new old) (let* ((article (navi2ch-article-url-to-article new)) (board (navi2ch-board-url-to-board new)) (file (navi2ch-article-get-file-name board article)) (regex (regexp-quote (navi2ch-replace-string ;; 鯖移転もあるので、鯖名まで削る "^http://[^.]+\\|/$" "" old 'all)))) (unless (file-exists-p file) (when (navi2ch-article-fetch-article board article) (navi2ch-bm-remember-fetched-article board article))) (when (file-exists-p file) (with-temp-buffer (navi2ch-insert-file-contents file) ;; 旧スレッドのURLが書いてあるかチェック (if (re-search-forward regex ;; 1-5をチェック (navi2ch-line-beginning-position 6) t) t ;; (navi2ch-bm-remove-article-subr board article) nil))))) (defun navi2ch-subject-seriese-format (subject) ;; 全角/半角を区別しない (setq subject (japanese-zenkaku subject)) (setq subject (japanese-hankaku subject 'ascii-only)) ;; 大文字/小文字を区別しない (setq subject (upcase subject)) ;; ひらがな/カタカナを区別しない (setq subject (japanese-hiragana subject)) ;; 空白・数字を無視 (setq subject (navi2ch-replace-string "[ \t0-9]" "" subject 'all))) (defun navi2ch-subject-seriese-p (subject1 subject2) ;; スレタイの比較ってどうやればいいのか分からん。 ;; とりあえず、全角/半角・ひらがな/カタカナを揃えた後で ;; 短いほうの前後10%づつを切り捨てて ;; (string-match "短い方" "長い方") としてる。 (unless (string= subject1 subject2) (let* ((subj1 (navi2ch-subject-seriese-format subject1)) (subj2 (navi2ch-subject-seriese-format subject2)) (ratio 0.1) from to) (when (> (length subj1) (length subj2)) (let ((tmp subj1)) (setq subj1 subj2 subj2 tmp))) (setq from (round (* (length subj1) ratio))) (unless (= from 0) (setq to (- from))) (string-match (regexp-quote (substring subj1 from to)) subj2)))) (defun navi2ch-article-search-new-thread-with-subject () ;; 類似サブジェクトのスレをチェック (let* ((article navi2ch-article-current-article) (board navi2ch-article-current-board) (subject (cdr (assoc 'subject article))) (curl (navi2ch-article-to-url board article)) (file (navi2ch-board-get-file-name board)) list nurl found) (unless navi2ch-offline (navi2ch-board-save-old-subject-file board) (navi2ch-board-update-file board)) (setq list (navi2ch-board-get-subject-list file)) (catch 'find (while list (let* ((atcl (car list)) (sbj (cdr (assoc 'subject atcl)))) (setq nurl (navi2ch-article-to-url board atcl) list (cdr list)) (when (and (navi2ch-subject-seriese-p subject sbj) (navi2ch-new-thread-check nurl curl)) (throw 'find (setq found t)))))) (if found nurl))) (defun navi2ch-article-search-new-thread-with-lead () ;; 新スレへの誘導をチェック (let ((cboard (cdr (assoc 'name navi2ch-article-current-board))) (curl (navi2ch-article-to-url navi2ch-article-current-board navi2ch-article-current-article)) (msg-list (reverse navi2ch-article-message-list)) (num 850) ;新スレ移行は850以降かな。 nboard url body start found) (catch 'find (while (> (length msg-list) num) (setq body (if (listp (cdar msg-list)) (cdr (assoc 'data (cdar msg-list))) (cdar msg-list)) msg-list (cdr msg-list)) (setq start 0) (while (string-match navi2ch-article-url-regexp body start) (setq url (match-string 0 body) start (match-end 0)) (setq nboard (cdr (assoc 'name (navi2ch-board-url-to-board url)))) ;; 同じ板だったらチェック (when (and nboard ;; 移転してても念のためチェック (or (string= nboard "No Name") (string= nboard cboard)) (navi2ch-new-thread-check url curl)) (throw 'find (setq found t)))) (setq num (1+ num)))) (if found url))) (defun navi2ch-article-new-thread () "新スレに移動する。" (interactive) (let ((url (or (navi2ch-article-search-new-thread-with-lead) (navi2ch-article-search-new-thread-with-subject)))) (if url (let* ((article (navi2ch-article-url-to-article url)) (board (navi2ch-board-url-to-board url)) (subj (navi2ch-article-cached-subject board article))) (when (navi2ch-y-or-n-p (concat "「" subj "」に移動する?")) (navi2ch-goto-url url))) (message (concat "新スレを発見できませんでした。" (substitute-command-keys "`\\[navi2ch-article-goto-current-board]'") " して手動で探してね。"))))) (define-key navi2ch-article-mode-map "\C-c\C-n" 'navi2ch-article-new-thread) (provide 'sinsure)