--- pukiwiki-mode.el.old 2004-09-07 09:46:33.000000000 +0900 +++ pukiwiki-mode.el 2004-09-07 18:29:06.000000000 +0900 @@ -248,6 +248,23 @@ :group 'pukiwiki :type '(integer :size 0)) +(defcustom pukiwiki-jump-display-window-top nil + "*Non-nil means displaying the pointer which moved at the top of a window." + :group 'pukiwiki + :type 'boolean) + +(defcustom pukiwiki-jump-display-window-top-without-content nil + "*Non-nil means excepting, if it is content +when displaying the pointer which moved at the top of a window." + :group 'pukiwiki + :type 'boolean) + +(defcustom pukiwiki-jump-display-window-upper-margin 0 + "*The margin of the window upper part when displaying the pointer +which moved at the top of a window." + :group 'pukiwiki + :type '(integer :size 0)) + ;;; 汎用関数 (defun pukiwiki-mode-version () @@ -791,7 +808,9 @@ (local-set-key "b" 'scroll-down) (local-set-key " " 'scroll-up) (local-set-key "e" 'pukiwiki-view-edit-current-page) - (local-set-key "\C-m" 'pukiwiki-edit-new-line) + (local-set-key "\C-m" 'pukiwiki-view-return-function) + (local-set-key "\C-i" 'pukiwiki-jump-anchor) + (local-set-key "\M-\C-i" 'pukiwiki-jump-anchor-prev) (local-set-key "\C-xv=" 'pukiwiki-index-show-diff) ) @@ -2542,16 +2561,21 @@ (defun pukiwiki-insert-contents () "目次を挿入する" - (let ((chapter nil) (lst nil)) + (let ((chapter nil) (lst nil) (list-cons nil) (number 0) (start nil)) (save-excursion (save-current-buffer (goto-char (point-min)) (while (re-search-forward "^[*]+[^\n\r]+" nil t) + (setq number (1+ number)) + (pukiwiki-set-content-anchor-property + (match-beginning 0) (match-end 0) 'header number) (setq chapter (cons - (buffer-substring-no-properties - (match-beginning 0) - (match-end 0)) + (cons + (buffer-substring-no-properties + (match-beginning 0) + (match-end 0)) + number) chapter))) (setq chapter (reverse chapter)) (goto-char (point-min)) @@ -2560,13 +2584,90 @@ (forward-line 1) (setq lst chapter) (while lst + (setq lst-cons (car lst)) + (setq start (1+ (point))) (insert (concat " " - (car lst) + (car lst-cons) "\n")) + (pukiwiki-set-content-anchor-property + start (1- (point)) 'content (cdr lst-cons)) (setq lst (cdr lst)))))))) +(defun pukiwiki-set-content-anchor-property (start end type value + &optional object) + (add-text-properties start end + (list 'anchor t 'anchortype type type value) + object) + (add-text-properties start (1+ start) (list 'anchorhead t) object)) + +(defun pukiwiki-view-return-function (&optional opt) + (interactive) + ;; anchor property が無ければ従来の動作を。 + (if (pukiwiki-point-anchor-p) + (pukiwiki-jump-content-anchor) + (pukiwiki-edit-new-line))) + +(defun pukiwiki-jump-content-anchor-1 (type value &optional object) + (let ((prev (point)) (type type) (value value) dest) + (goto-char (point-min)) + (setq jump-function 'next-single-property-change)) + (if (setq dest + (pukiwiki-search-point-of-destination jump-function type value)) + (let ((dest dest)) + (goto-char dest) + (if (and pukiwiki-jump-display-window-top + (if pukiwiki-jump-display-window-top-without-content + (not (pukiwiki-point-anchor-content-p)) t)) + (let ((current dest) start) + (save-excursion + (forward-line (- 0 pukiwiki-jump-display-window-upper-margin)) + (setq start (point))) + (set-window-start (selected-window) start)))))) + +(defun pukiwiki-jump-content-anchor (&optional object) + (interactive) + (let* ((atype (get-text-property (point) 'anchortype)) + (value (get-text-property (point) atype)) + type) + (cond + ((eq atype 'content) (setq type 'header)) + ((eq atype 'header) (setq type 'content))) + (pukiwiki-jump-content-anchor-1 type value))) + +(defun pukiwiki-point-anchor-p () + (get-text-property (point) 'anchor)) + +(defun pukiwiki-point-anchor-content-p () + (eq 'content (get-text-property (point) 'anchortype))) + +(defun pukiwiki-jump-anchor (&optional opt) + (interactive "P") + (let* ((way opt) dest) + (if way (setq jump-function 'previous-single-property-change) + (setq jump-function 'next-single-property-change)) + (if (setq dest + (pukiwiki-search-point-of-destination jump-function 'anchorhead)) + (goto-char dest)))) + +(defun pukiwiki-jump-anchor-prev (&optional opt) + (interactive "P") + (pukiwiki-jump-anchor t)) + +(defun pukiwiki-search-point-of-destination (func type &optional value) + (save-excursion + (let ((function func) + (prop type) + (value value) dest) + (if (catch 'reaching + (while (setq dest (funcall function (point) prop)) + (goto-char dest) + (let ((pvalue (get-text-property (point) prop))) + (when (if value (and pvalue (= pvalue value)) pvalue) + (throw 'reaching t))))) + (point))))) + (defun pukiwiki-insert-ls2 () (goto-char (point-min)) (when pukiwiki-index-page-info-list