Advertisement
Guest User

Navi2ch subject format patch

a guest
May 14th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- navi2ch-board.el 2012-03-31 22:16:19.000000000 +0900
  2. +++ navi2ch-board.el 2012-05-15 00:38:56.331688741 +0900
  3. @@ -281,12 +281,34 @@
  4. (when (looking-at regexp)
  5. (throw 'loop regexp))))))
  6.  
  7. +(defsubst navi2ch-board-generate-article-info (article seen current-time)
  8. + (let ((res (cdr (assq 'response article)))
  9. + (artid (cdr (assq 'artid article)))
  10. + (hash (make-hash-table :test 'eq))
  11. + last read)
  12. + (puthash 'res res hash)
  13. + (puthash 'artid artid hash)
  14. + (puthash 'elapsed (- current-time (string-to-number artid)) hash)
  15. + (when navi2ch-board-insert-subject-with-diff
  16. + (setq last (or seen
  17. + (cdr (assoc artid navi2ch-board-last-seen-alist))
  18. + (catch 'break
  19. + (string-to-number
  20. + (or (cdr (assoc artid navi2ch-board-old-subject-alist))
  21. + (throw 'break nil))))))
  22. + (puthash 'diff (if last (- (string-to-number res) last) nil) hash))
  23. + (when navi2ch-board-insert-subject-with-unread
  24. + (setq read (navi2ch-article-get-last-read-number
  25. + navi2ch-board-current-board article))
  26. + (puthash 'unread (if read (max 0 (- (string-to-number res) read)) nil) hash))
  27. + hash))
  28.  
  29. (defun navi2ch-board-insert-subjects (list)
  30. (let ((bookmark (cdr (assq 'bookmark navi2ch-board-current-board)))
  31. (hide (cdr (assq 'hide navi2ch-board-current-board)))
  32. (summary (navi2ch-article-load-article-summary
  33. navi2ch-board-current-board))
  34. + (ct (current-time))
  35. (i 1))
  36. (dolist (article list)
  37. (let* ((artid (cdr (assq 'artid article)))
  38. @@ -307,39 +329,8 @@
  39. (navi2ch-bm-insert-subject
  40. article i
  41. (cdr (assq 'subject article))
  42. - (let ((res (cdr (assq 'response article)))
  43. - (last (and navi2ch-board-insert-subject-with-diff
  44. - (or seen
  45. - (cdr (assoc artid navi2ch-board-last-seen-alist))
  46. - (catch 'break
  47. - (string-to-number
  48. - (or (cdr (assoc artid navi2ch-board-old-subject-alist))
  49. - (throw 'break nil)))))))
  50. - (read (and navi2ch-board-insert-subject-with-unread
  51. - (navi2ch-article-get-last-read-number
  52. - navi2ch-board-current-board
  53. - article))))
  54. - (concat "("
  55. - (format "%4s" res)
  56. - (and navi2ch-board-insert-subject-with-diff
  57. - (concat
  58. - "/"
  59. - (if last
  60. - (format "%5s"
  61. - (format "+%d"
  62. - (- (string-to-number res) last)))
  63. - " -")))
  64. - (and navi2ch-board-insert-subject-with-unread
  65. - (concat
  66. - "/"
  67. - (if read
  68. - (substring
  69. - (format " Δ%d"
  70. - (max 0
  71. - (- (string-to-number res) read)))
  72. - -5)
  73. - " -")))
  74. - ")"))
  75. + (navi2ch-board-generate-article-info
  76. + article seen (+ (* (car ct) 65536) (nth 1 ct)))
  77. (cond ((and navi2ch-board-check-updated-article-p
  78. (setq updated
  79. (navi2ch-board-updated-article-p article seen)))
  80. @@ -357,6 +348,7 @@
  81. (eq old-mode major-mode))
  82. (navi2ch-board-sync force)
  83. (setq navi2ch-board-current-board (navi2ch-board-load-info board))
  84. + (navi2ch-bm-set-subject-format-info (cdr (assq 'id board)))
  85. (run-hooks 'navi2ch-board-select-board-hook)
  86. (navi2ch-board-sync force 'first)))))
  87.  
  88. --- navi2ch-board-misc.el 2012-03-31 22:16:19.000000000 +0900
  89. +++ navi2ch-board-misc.el 2012-05-15 06:50:57.398940227 +0900
  90. @@ -125,6 +125,16 @@
  91. (nil . ? ))
  92. :test 'eq))
  93.  
  94. +;; 現在の板のスレタイ一覧の書式情報
  95. +(defvar navi2ch-bm-subject-current-format-info
  96. + (navi2ch-alist-to-hash
  97. + '((format)
  98. + (number-pos)
  99. + (updated-pos)
  100. + (state-pos)
  101. + (mark-pos)
  102. + (subject-pos))
  103. + :test 'eq))
  104.  
  105. (eval-and-compile
  106. (let ((state-list '(view cache update down nil))
  107. @@ -254,29 +264,148 @@
  108. (t
  109. (navi2ch-article-check-cached board article))))
  110.  
  111. +(defun navi2ch-bm-set-subject-format-info (&optional board-id)
  112. + "渡された板IDに対応する書式を選択し、各列の開始位置を求める"
  113. + (puthash
  114. + 'format (if (or (functionp navi2ch-bm-subject-format) (stringp navi2ch-bm-subject-format))
  115. + navi2ch-bm-subject-format
  116. + (catch 'found
  117. + (let (kv v (fmts navi2ch-bm-subject-format))
  118. + (while (setq kv (car fmts))
  119. + (if (setq v (cdr kv)) (if (member board-id v) (throw 'found (car kv))))
  120. + (setq fmts (cdr fmts))))
  121. + (car (car navi2ch-bm-subject-format))))
  122. + navi2ch-bm-subject-current-format-info)
  123. + (let ((dummy-line (navi2ch-bm-format-subject
  124. + 999 ?\r ?\v "\f"
  125. + (navi2ch-alist-to-hash
  126. + '((res . "1") (diff) (unread) (artid . "1") (elapsed . 1) (mark . ?\a)))))
  127. + kv pos)
  128. + (if (setq pos (string-match "999" dummy-line))
  129. + (puthash 'number-pos (- pos 3) navi2ch-bm-subject-current-format-info))
  130. + (dolist (kv '((updated-pos . "\r") (state-pos . "\v") (mark-pos . "\a") (subject-pos . "\f")))
  131. + (puthash (car kv)
  132. + (string-match (cdr kv) dummy-line)
  133. + navi2ch-bm-subject-current-format-info))))
  134. +
  135. (defun navi2ch-bm-format-subject
  136. (number updated-char state-char subject other)
  137. - (format (concat "%" (number-to-string navi2ch-bm-number-width)
  138. - "d %c%c %s%s%s\n")
  139. - number updated-char state-char subject
  140. - (make-string (max (- navi2ch-bm-subject-width
  141. - (string-width subject))
  142. - 1)
  143. - ? )
  144. - other))
  145. + "other が文字列のときは navi2ch-bm-subject-current-format-info を適用後、後ろに連結する"
  146. + (let* ((format (gethash 'format navi2ch-bm-subject-current-format-info))
  147. + (info (if (hash-table-p other)
  148. + (copy-hash-table other) (make-hash-table :test 'eq)))
  149. + (res (string-to-number (gethash 'res info "")))
  150. + (diff (gethash 'diff info 'NIL))
  151. + (unread (gethash 'unread info 'NIL))
  152. + (id (gethash 'artid info ""))
  153. + (elapsed (gethash 'elapsed info 9999999999)))
  154. + (unless format
  155. + (navi2ch-bm-set-subject-format-info)
  156. + (setq format (gethash 'format navi2ch-bm-subject-current-format-info)))
  157. + (concat
  158. + (if (functionp format)
  159. + (funcall format
  160. + number updated-char state-char subject res diff unread id
  161. + (/ res (/ elapsed 60.0))
  162. + (min (/ res (/ elapsed 3600.0)) (* res 4.0))
  163. + (min (/ res (/ elapsed 86400.0)) res)
  164. + (gethash 'mark info))
  165. + (let ((line format))
  166. + (if (string-match "<number>" line)
  167. + (setq line (replace-match
  168. + (format (concat "%" (number-to-string navi2ch-bm-number-width) "d")
  169. + number)
  170. + nil nil line)))
  171. + (if (string-match "<updated>" line)
  172. + (setq line (replace-match (format "%c" updated-char) nil nil line)))
  173. + (if (string-match "<state>" line)
  174. + (setq line (replace-match (format "%c" state-char) nil nil line)))
  175. + (if (string-match "<mark>" line)
  176. + (setq line (replace-match
  177. + (format "%c" (or (cdr (and (listp other) (assoc 'mark other))) ? ))
  178. + nil nil line)))
  179. + (if (string-match "<res\\(:\\([0-9]+\\)\\)?>" line)
  180. + (setq line (replace-match
  181. + (format (concat "%" (or (match-string 2 line) "4") "d") res)
  182. + nil nil line)))
  183. + (if (string-match "<diff\\(:\\([0-9]+\\)\\)?>" line)
  184. + (setq line (replace-match
  185. + (if (eq diff 'NIL)
  186. + ""
  187. + (format (if (match-string 1 line)
  188. + (concat "%" (match-string 2 line) "s") "/%5s")
  189. + (if diff (format "+%d" diff) "-")))
  190. + nil nil line)))
  191. + (if (string-match "<unread\\(:\\([0-9]+\\)\\)?>" line)
  192. + (setq line (replace-match
  193. + (if (eq unread 'NIL)
  194. + ""
  195. + (if unread
  196. + (if (match-string 1 line)
  197. + (substring (format " Δ%d" unread)
  198. + (- (string-to-number (match-string 2 line))))
  199. + (concat "/" (substring (format " Δ%d" unread) -5)))
  200. + (format (concat "%" (or (match-string 2 line) "5") "s") "-")))
  201. + nil nil line)))
  202. + (if (string-match "<id\\(:\\([0-9]+\\)\\)?>" line)
  203. + (setq line (replace-match
  204. + (if (match-string 1 line)
  205. + (format (concat "%" (match-string 2 line) "s") id)
  206. + id)
  207. + nil nil line)))
  208. + (if (string-match "<momentum_m\\(:\\([.0-9]+\\)\\)?>" line)
  209. + (setq line (replace-match
  210. + (format (concat "%" (or (match-string 2 line) "4.1") "f")
  211. + (if (<= elapsed 0) 0 (/ res (/ elapsed 60.0))))
  212. + nil nil line)))
  213. + (if (string-match "<momentum_h\\(:\\([.0-9]+\\)\\)?>" line)
  214. + (setq line (replace-match
  215. + (format (concat "%" (or (match-string 2 line) "6.1") "f")
  216. + (if (<= elapsed 0) 0 (min (/ res (/ elapsed 3600.0)) (* res 4.0))))
  217. + nil nil line)))
  218. + (if (string-match "<momentum_d\\(:\\([.0-9]+\\)\\)?>" line)
  219. + (setq line (replace-match
  220. + (format (concat "%" (or (match-string 2 line) "5.1") "f")
  221. + (if (<= elapsed 0) 0 (min (/ res (/ elapsed 86400.0)) res)))
  222. + nil nil line)))
  223. + (if (string-match "<subject>" line)
  224. + (setq line (replace-match
  225. + (concat subject
  226. + (make-string (max (- navi2ch-bm-subject-width
  227. + (string-width subject)) 1) ? ))
  228. + nil t line)))))
  229. + (if (stringp other) other)
  230. + "\n")))
  231.  
  232. +;; navi2ch-articles.el, navi2ch-board.el, navi2ch-bookmark.el
  233. +;; navi2ch-directory.el, navi2ch-history.el, navi2ch-search.el
  234. (defun navi2ch-bm-insert-subject (item number subject other
  235. &optional updated)
  236. (let* ((article (navi2ch-bm-get-article-internal item))
  237. (board (navi2ch-bm-get-board-internal item))
  238. (point (point))
  239. (state (navi2ch-bm-get-state-from-article board article))
  240. + (info (if (hash-table-p other)
  241. + (copy-hash-table other)
  242. + (let ((hash (make-hash-table :test 'eq))
  243. + (res (assoc 'response article))
  244. + (id (assoc 'artid article))
  245. + (ct (current-time)))
  246. + (if (and (not res) (not id))
  247. + other
  248. + (setq subject (concat subject other))
  249. + (puthash 'res (cdr res) hash)
  250. + (when (setq id (cdr id))
  251. + (puthash 'artid id hash)
  252. + (puthash 'elapsed (- (+ (* (car ct) 65536) (nth 1 ct))
  253. + (string-to-number id)) hash))
  254. + hash))))
  255. (string (navi2ch-bm-format-subject
  256. number
  257. (gethash updated navi2ch-bm-updated-mark-table)
  258. (gethash state navi2ch-bm-state-char-table)
  259. (or subject navi2ch-bm-empty-subject)
  260. - other)))
  261. + info)))
  262. ;; for contrib/izonmoji-mode.el
  263. (navi2ch-ifxemacs
  264. (insert string)
  265. @@ -311,42 +440,51 @@
  266. (navi2ch-list)))))
  267.  
  268. ;;; goto-*-column
  269. -(defsubst navi2ch-bm-goto-updated-mark-column ()
  270. - (beginning-of-line)
  271. - (when (looking-at " *[0-9]+ ")
  272. - (goto-char (match-end 0))))
  273. -
  274. -(defsubst navi2ch-bm-goto-state-column ()
  275. - (when (navi2ch-bm-goto-updated-mark-column)
  276. - (forward-char 1)))
  277. -
  278. -(defsubst navi2ch-bm-goto-mark-column ()
  279. - (when (navi2ch-bm-goto-updated-mark-column)
  280. - (forward-char 2)))
  281. -
  282. -(defun navi2ch-bm-goto-other-column ()
  283. - (let ((sbj (cdr
  284. - (assq 'subject
  285. - (navi2ch-bm-get-article-internal
  286. - (navi2ch-bm-get-property-internal (point)))))))
  287. - (navi2ch-bm-goto-mark-column)
  288. - (forward-char 1)
  289. - (unless sbj (setq sbj navi2ch-bm-empty-subject))
  290. - (when (and (not (string= sbj ""))
  291. - (search-forward sbj nil t))
  292. - (goto-char (match-end 0)))
  293. - (skip-chars-forward " ")))
  294. +;; バッファの文字列から直接探索するのやめて、内部変数もしくは text-property から
  295. +;; 取得するようにしたのでこれらをコメントアウト
  296. +;;
  297. +;; (defsubst navi2ch-bm-goto-updated-mark-column ()
  298. +;; (beginning-of-line)
  299. +;; (when (looking-at " *[0-9]+ ")
  300. +;; (goto-char (match-end 0))))
  301. +;;
  302. +;; (defsubst navi2ch-bm-goto-state-column ()
  303. +;; (when (navi2ch-bm-goto-updated-mark-column)
  304. +;; (forward-char 1)))
  305. +;;
  306. +;; (defsubst navi2ch-bm-goto-mark-column ()
  307. +;; (when (navi2ch-bm-goto-updated-mark-column)
  308. +;; (forward-char 2)))
  309. +;;
  310. +;; (defun navi2ch-bm-goto-other-column ()
  311. +;; (let ((sbj (cdr
  312. +;; (assq 'subject
  313. +;; (navi2ch-bm-get-article-internal
  314. +;; (navi2ch-bm-get-property-internal (point)))))))
  315. +;; (navi2ch-bm-goto-mark-column)
  316. +;; (forward-char 1)
  317. +;; (unless sbj (setq sbj navi2ch-bm-empty-subject))
  318. +;; (when (and (not (string= sbj ""))
  319. +;; (search-forward sbj nil t))
  320. +;; (goto-char (match-end 0)))
  321. +;; (skip-chars-forward " ")))
  322.  
  323.  
  324. (defun navi2ch-bm-insert-state (item state &optional updated)
  325. - ;; (setq article (navi2ch-put-alist 'cache 'view article))
  326. - (let ((buffer-read-only nil))
  327. + (let ((buffer-read-only nil)
  328. + (updated-pos (gethash 'updated-pos navi2ch-bm-subject-current-format-info))
  329. + (state-pos (gethash 'state-pos navi2ch-bm-subject-current-format-info)))
  330. (save-excursion
  331. - (navi2ch-bm-goto-state-column)
  332. - (backward-char 1)
  333. - (delete-char 2)
  334. - (insert (gethash updated navi2ch-bm-updated-mark-table)
  335. - (gethash state navi2ch-bm-state-char-table))
  336. + (when updated-pos
  337. + (beginning-of-line)
  338. + (forward-char updated-pos)
  339. + (delete-char 1)
  340. + (insert (gethash updated navi2ch-bm-updated-mark-table)))
  341. + (when state-pos
  342. + (beginning-of-line)
  343. + (forward-char state-pos)
  344. + (delete-char 1)
  345. + (insert (gethash state navi2ch-bm-state-char-table)))
  346. (navi2ch-bm-set-property (navi2ch-line-beginning-position)
  347. (navi2ch-line-end-position)
  348. item state updated))))
  349. @@ -569,24 +707,23 @@
  350.  
  351. (defun navi2ch-bm-renumber ()
  352. (interactive)
  353. - (save-excursion
  354. - (goto-char (point-min))
  355. - (let ((buffer-read-only nil)
  356. - (i 1))
  357. - (while (not (eobp))
  358. - (let ((props (text-properties-at (point)))
  359. - (num-string (format
  360. - (concat "%" (number-to-string navi2ch-bm-number-width) "d")
  361. - i)))
  362. - (delete-region (point)
  363. - (save-excursion
  364. - (navi2ch-bm-goto-state-column)
  365. - (- (point) 2)))
  366. - (insert num-string)
  367. - (set-text-properties (- (point) (length num-string))
  368. - (point) props)
  369. - (forward-line 1)
  370. - (setq i (1+ i)))))))
  371. + (let ((number-pos (gethash 'number-pos navi2ch-bm-subject-current-format-info))
  372. + (number-format (concat "%" (number-to-string navi2ch-bm-number-width) "d")))
  373. + (if number-pos
  374. + (save-excursion
  375. + (goto-char (point-min))
  376. + (let ((buffer-read-only nil) (i 1))
  377. + (while (not (eobp))
  378. + (let ((props (text-properties-at (point)))
  379. + (number-string (format number-format i)))
  380. + (delete-region (+ (point) number-pos)
  381. + (save-excursion
  382. + (re-search-forward "[0-9]+" nil t 1)))
  383. + (insert number-string)
  384. + (set-text-properties (- (point) (length number-string))
  385. + (point) props)
  386. + (forward-line 1)
  387. + (setq i (1+ i)))))))))
  388.  
  389. (defun navi2ch-bm-view-logo ()
  390. "その板のロゴを見る。"
  391. @@ -656,17 +793,19 @@
  392. ARG が non-nil なら移動方向を逆にする。"
  393. (let ((item (navi2ch-bm-get-property-internal (point)))
  394. (state (navi2ch-bm-get-state (point)))
  395. - (table (and mark navi2ch-bm-state-mark-face-table)))
  396. - (when item
  397. - (let ((buffer-read-only nil)
  398. - (pos (point)))
  399. - (navi2ch-bm-goto-mark-column)
  400. - (delete-char 1)
  401. - (insert (if mark ?* ? ))
  402. - (navi2ch-bm-set-property (navi2ch-line-beginning-position)
  403. - (navi2ch-line-end-position)
  404. - item state nil table)
  405. - (goto-char pos)))
  406. + (table (and mark navi2ch-bm-state-mark-face-table))
  407. + (mark-pos (gethash 'mark-pos navi2ch-bm-subject-current-format-info))
  408. + (buffer-read-only nil))
  409. + (save-excursion
  410. + (if mark-pos
  411. + (when item
  412. + (beginning-of-line)
  413. + (forward-char mark-pos)
  414. + (delete-char 1)
  415. + (insert (if mark ?* ? ))))
  416. + (navi2ch-bm-set-property (navi2ch-line-beginning-position)
  417. + (navi2ch-line-end-position)
  418. + item state nil table))
  419. (when (and navi2ch-bm-mark-and-move interactive)
  420. (let (downward)
  421. (cond ((eq navi2ch-bm-mark-and-move 'follow)
  422. @@ -690,17 +829,15 @@
  423. (save-excursion
  424. (goto-char (point-min))
  425. (while (not (eobp))
  426. - (navi2ch-bm-goto-mark-column)
  427. - (if (looking-at "\\*")
  428. - (progn
  429. - (condition-case nil
  430. - (save-excursion
  431. - (navi2ch-bm-unmark)
  432. - (apply func args))
  433. - (navi2ch-update-failed nil))
  434. - (sit-for 0)
  435. - (discard-input))
  436. - (forward-line)))))
  437. + (when (get-text-property (point) 'navi2ch-bm-mark)
  438. + (condition-case nil
  439. + (save-excursion
  440. + (navi2ch-bm-unmark)
  441. + (apply func args))
  442. + (navi2ch-update-failed nil))
  443. + (sit-for 0)
  444. + (discard-input))
  445. + (forward-line))))
  446.  
  447. (defsubst navi2ch-bm-display-mark-article ()
  448. (interactive)
  449. @@ -754,7 +891,7 @@
  450. "更新されている可能性のあるスレを fetch する。"
  451. (interactive)
  452. (unless navi2ch-offline
  453. - (navi2ch-bm-mark-states "[^=]")
  454. + (navi2ch-bm-mark-states '(updated new updated nil)) ; 元の引数は[^=]
  455. (sit-for 0)
  456. (navi2ch-bookmark-fetch-mark-article)))
  457.  
  458. @@ -764,18 +901,31 @@
  459.  
  460. (defun navi2ch-bm-mark-marks (mark &optional arg)
  461. (interactive "cInput mark: \nP")
  462. - (navi2ch-bm-mark-states
  463. - (format ".%c" (upcase mark))
  464. - arg))
  465. -
  466. -(defun navi2ch-bm-mark-states (regexp &optional arg)
  467. - (save-excursion
  468. - (goto-char (point-min))
  469. - (while (not (eobp))
  470. - (navi2ch-bm-goto-updated-mark-column)
  471. - (when (looking-at regexp)
  472. - (navi2ch-bm-mark-subr (not arg)))
  473. - (forward-line))))
  474. + (let* ((m (upcase mark))
  475. + (target (cond
  476. + ((eq m ?%) '(updated new))
  477. + ((eq m ?+) '(updated updated))
  478. + ((eq m ?=) '(updated seen))
  479. + ((eq m ? ) '(updated))
  480. + ((eq m ?V) '(state view))
  481. + ((eq m ?C) '(state cache))
  482. + ((eq m ?U) '(state update))
  483. + ((eq m ?D) '(state down))
  484. + ((eq m ? ) '(state)))))
  485. + (if target (navi2ch-bm-mark-states target arg))))
  486. +
  487. +;; 指定した状態のスレ全てをマークする (引数を正規表現からリストに変更)
  488. +(defun navi2ch-bm-mark-states (target &optional arg)
  489. + (let ((bm-get (if (eq (car target) 'updated) 'navi2ch-bm-get-updated-mark
  490. + (if (eq (car target) 'state) 'navi2ch-bm-get-state)))
  491. + (target-states (cdr target)))
  492. + (if bm-get
  493. + (save-excursion
  494. + (goto-char (point-min))
  495. + (while (not (eobp))
  496. + (if (member (funcall bm-get) target-states)
  497. + (navi2ch-bm-mark-subr (not arg)))
  498. + (forward-line))))))
  499.  
  500. ;; mark by regexp query
  501. (defun navi2ch-bm-mark-by-query (query &optional arg)
  502. @@ -795,29 +945,31 @@
  503.  
  504. (defun navi2ch-bm-sort-by-number (&optional rev)
  505. (interactive "P")
  506. - (navi2ch-bm-sort-subr
  507. - rev
  508. - (lambda ()
  509. - (beginning-of-line)
  510. - (save-match-data
  511. - (if (looking-at "^ *\\([0-9]+\\)")
  512. - (string-to-number
  513. - (buffer-substring (match-beginning 1) (match-end 1)))
  514. - ;; not a number
  515. - -1)))
  516. - nil))
  517. + (let* ((i 0)
  518. + (table (mapcar (lambda (item)
  519. + (setq i (+ i 1)) (cons (cdr (assoc 'artid item)) i))
  520. + navi2ch-board-subject-list)))
  521. + (navi2ch-bm-sort-subr
  522. + rev
  523. + (lambda ()
  524. + (cdr (assoc (cdr (assq 'artid
  525. + (navi2ch-bm-get-article-internal
  526. + (navi2ch-bm-get-property-internal (point)))))
  527. + table)))
  528. + nil)))
  529.  
  530. (defun navi2ch-bm-sort-by-state (&optional rev)
  531. (interactive "P")
  532. (navi2ch-bm-sort-subr
  533. rev
  534. (lambda ()
  535. - (navi2ch-bm-goto-state-column)
  536. - (backward-char)
  537. - (or (cdr (assoc (buffer-substring (point) (+ (point) 2))
  538. - navi2ch-bm-sort-by-state-order))
  539. - ;; 未知の状態。
  540. - 1000))
  541. + (let ((state (navi2ch-bm-get-state)))
  542. + (cond
  543. + ((eq state 'view) 1)
  544. + ((eq state 'cache) 2)
  545. + ((eq state 'update) 3)
  546. + ((eq state 'down) 4)
  547. + (t 1000))))
  548. nil))
  549.  
  550. (defun navi2ch-bm-sort-by-subject (&optional rev)
  551. @@ -825,18 +977,36 @@
  552. (navi2ch-bm-sort-subr
  553. rev
  554. (lambda ()
  555. - (navi2ch-bm-goto-mark-column)
  556. - (forward-char 1))
  557. - 'navi2ch-bm-goto-other-column))
  558. + (cdr (assq 'subject
  559. + (navi2ch-bm-get-article-internal
  560. + (navi2ch-bm-get-property-internal (point))))))
  561. + nil))
  562.  
  563. -(defun navi2ch-bm-sort-by-other (&optional rev)
  564. +(defun navi2ch-bm-sort-by-res (&optional rev)
  565. (interactive "P")
  566. (navi2ch-bm-sort-subr
  567. rev
  568. (lambda ()
  569. - (navi2ch-bm-goto-other-column)
  570. - nil) ; end-key-fun を呼ばせるには nil が欲しいらしい。はまった(泣)。
  571. - 'end-of-line))
  572. + (string-to-number
  573. + (cdr (assq 'response
  574. + (navi2ch-bm-get-article-internal
  575. + (navi2ch-bm-get-property-internal (point)))))))
  576. + nil))
  577. +
  578. +(defun navi2ch-bm-sort-by-other (&optional rev)
  579. + (interactive "P")
  580. + (let ((subject-pos (gethash 'subject-pos navi2ch-bm-subject-current-format-info))
  581. + len)
  582. + (navi2ch-bm-sort-subr
  583. + rev
  584. + (lambda ()
  585. + (setq len (length (cdr (assq 'subject
  586. + (navi2ch-bm-get-article-internal
  587. + (navi2ch-bm-get-property-internal (point)))))))
  588. + (forward-char (+ subject-pos len))
  589. + (re-search-forward " *")
  590. + nil) ; end-key-fun を呼ばせるには nil が欲しいらしい。はまった(泣)。
  591. + 'end-of-line)))
  592.  
  593. (defun navi2ch-bm-sort-by-date (&optional rev)
  594. (interactive "P")
  595. @@ -851,17 +1021,19 @@
  596.  
  597. (defun navi2ch-bm-sort (&optional arg)
  598. (interactive "P")
  599. - (let ((ch (navi2ch-read-char-with-retry
  600. - "Sort by n)umber s)tate t)itle o)ther d)ate? "
  601. - nil '(?n ?s ?t ?o ?d))))
  602. + (let* ((ch (navi2ch-read-char-with-retry
  603. + "Sort by n)umber s)tate t)itle r)es o)ther d)ate? (If input upper case, in reverse) "
  604. + nil '(?n ?s ?t ?r ?o ?d ?N ?S ?T ?R ?O ?D)))
  605. + (uch (upcase ch)))
  606. (message "Sorting...")
  607. (funcall
  608. - (cond ((eq ch ?n) 'navi2ch-bm-sort-by-number)
  609. - ((eq ch ?s) 'navi2ch-bm-sort-by-state)
  610. - ((eq ch ?t) 'navi2ch-bm-sort-by-subject)
  611. - ((eq ch ?o) 'navi2ch-bm-sort-by-other)
  612. - ((eq ch ?d) 'navi2ch-bm-sort-by-date))
  613. - arg)
  614. + (cond ((eq uch ?N) 'navi2ch-bm-sort-by-number)
  615. + ((eq uch ?S) 'navi2ch-bm-sort-by-state)
  616. + ((eq uch ?T) 'navi2ch-bm-sort-by-subject)
  617. + ((eq uch ?R) 'navi2ch-bm-sort-by-res)
  618. + ((eq uch ?O) 'navi2ch-bm-sort-by-other)
  619. + ((eq uch ?D) 'navi2ch-bm-sort-by-date))
  620. + (if (eq uch ch) (not arg) arg))
  621. (message "Sorting...done")))
  622.  
  623. ;;; search
  624. --- navi2ch-bookmark.el 2012-03-31 22:16:19.000000000 +0900
  625. +++ navi2ch-bookmark.el 2012-05-13 19:31:10.674202203 +0900
  626. @@ -430,8 +430,7 @@
  627. (let ((board-data-cache (navi2ch-make-cache nil 'equal)))
  628. (goto-char (point-min))
  629. (while (not (eobp))
  630. - (navi2ch-bm-goto-mark-column)
  631. - (when (looking-at "\\*")
  632. + (when (get-text-property (point) 'navi2ch-bm-mark)
  633. (let* ((item (navi2ch-bm-get-property-internal (point)))
  634. (board (navi2ch-bm-get-board-internal item))
  635. (article (navi2ch-bm-get-article-internal item))
  636. --- navi2ch-vars.el 2012-03-31 22:16:19.000000000 +0900
  637. +++ navi2ch-vars.el 2012-05-15 06:04:08.081118868 +0900
  638. @@ -376,6 +376,68 @@
  639. :type 'boolean
  640. :group 'navi2ch-board)
  641.  
  642. +(defcustom navi2ch-bm-subject-format
  643. + "<number> <updated><state><mark><subject> (<res><diff><unread>)"
  644. + "*スレッド一覧の書式を定義する。
  645. +
  646. +レス数を左に表示する例:
  647. +\(setq navi2ch-bm-subject-format
  648. + \"<number> <updated><state><mark><res><diff><unread> <subject>\")
  649. +
  650. +文字列で指定した場合の置き換え文字列一覧
  651. +<number> スレッド番号 (幅は navi2ch-bm-number-width で指定)
  652. +<updated> updated-mark (幅は1文字固定)
  653. +<state> state (幅は1文字固定)
  654. +<mark> マーク表示の文字位置 (幅は1文字固定)
  655. +<subject> スレタイ
  656. +<res> レス数
  657. +<diff> 増加数(navi2ch-board-insert-subject-with-diff が nil なら空文字になる)
  658. +<unread> 未読数(navi2ch-board-insert-subject-with-unread が nil なら空文字になる)
  659. +<id> スレッドID
  660. +<momentum_m> 1分あたりの勢い
  661. +<momentum_h> 1時間あたりの勢い
  662. +<momentum_d> 1日あたりの勢い
  663. +
  664. +res,diff,unread,id は列幅を '<NAME:X>' のように指定可能。 (printfの%d)
  665. +momentum_* は列幅を '<NAME:X.Y>' のように指定可能。(printfの%f)
  666. +例えば <momentum_h:6.2> とすると ' 10.22' のように展開される。
  667. +
  668. +板別の指定方法として書式をキー,板IDを値としたリストで指定することも可能。
  669. +その場合はデフォルト値として板IDが空のものを定義しておくこと。
  670. +例:
  671. +\(setq navi2ch-bm-subject-format
  672. + '((\"<number> <updated><state><mark><res> <momentum_h>/h <subject>\")
  673. + (\"<number> <updated><state><mark><res> <momentum_d>/d <subject>\" . (\"unix\" \"linux\"))))
  674. +
  675. +関数で指定することでより細かく制御することもできる。
  676. +その場合は引数として、上記の置き換え文字列に相当する値が順に渡される。
  677. +条件によって各値は nil もしくは \"\" となることもあるので注意。
  678. +また、navi2ch-bm-number-width も正しく設定すること。
  679. +例:
  680. +\(defun my-subject-format
  681. + (number updated state subject res diff unread id momentum_m momentum_h momentum_d mark)
  682. + (format \"%5d %c%c%c%4d\%4s\%4s %5.2f/d %s\"
  683. + number updated state (or mark ? ) res
  684. + (if (symbolp diff) (if diff \"\" \"-\") diff)
  685. + (if (symbolp unread) (if unread \"\" \"-\") unread)
  686. + (max 0 momentum_d) subject))
  687. +\(setq navi2ch-bm-number-width 5)
  688. +\(setq navi2ch-bm-subject-format
  689. + '((\"<number> <updated><state><mark><res> <momentum_h>/h <subject>\")
  690. + (my-subject-format . (\"unix\" \"linux\"))))
  691. +"
  692. + :type '(choice (string :tag "定義文字列")
  693. + (function :tag "定義関数")
  694. + (repeat :tag "適用条件"
  695. + (cons :tag "定義"
  696. + (choice :tag "文字列か関数か"
  697. + (string :tag "文字列")
  698. + (function :tag "関数"))
  699. + (choice :tag "適用する板"
  700. + (const :tag "デフォルト" nil)
  701. + (repeat :tag "板別" (string :tag "ID"))))))
  702. + :group 'navi2ch-board)
  703. +
  704. (defcustom navi2ch-bm-subject-width 50
  705. "*各スレの題名の幅。"
  706. :type 'integer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement