[Date Prev] [Date Index] [Date Next]
[Thread Prev] [Thread Index] [Thread Next]

[xyzzy:01336] Re: 文字列のロック



mwakaharaさん、こんにちは。

        Tue, 1 Dec 1998 20:22:51 +0900 の
        [xyzzy:01333] Re: 文字列のロック
        への返事です.

| んじゃ、最初の「>」か「;」を探し、その次の文字をnarrowの開始,すぐ次の「<」
| か「&」を探し、その前の文字をnarrowの終了として、その間をnarrowするっていう
| のはどうでしょうか?

うーん、こんなんなんだろうか? なんか違うような気がする。使い物
になるか分かりませんが、とりあえず作ってみました。M-x foo-mode 
で on/off できます。移動はカーソルの上下左右です。あまりテスト
していないので無限ループにはまるかもしれませんが、帰ってこなく
なった場合はすかさず C-g してください。

(defvar *foo-regexp* "<[^>]+>\\|&[A-Za-z]*;")
(defvar-local foo-mode nil)

(defun foo-forward-char (&optional back)
  (interactive)
  (if (forward-char (if back -1 1))
      t
    (let ((obeg (point-min))
	  (oend (point-max)))
      (loop
	(widen)
	(unless (scan-buffer *foo-regexp*
			     :regexp t :reverse back :tail (not back) :no-dup back)
	  (narrow-to-region obeg oend)
	  (return nil))
	(let ((beg (point)))
	  (unless (scan-buffer *foo-regexp*
			       :regexp t :reverse back :tail back :no-dup back)
	    (narrow-to-region (point) (if back (point-min) (point-max)))
	    (return nil))
	  (narrow-to-region beg (point))
	  (goto-char (point-min))
	  (skip-chars-forward " \t\n")
	  (unless (eobp)
	    (goto-char (if back (point-max) (point-min)))
	    (if (and back (bolp))
		(forward-char -1))
	    (return t)))))))

(defun foo-backward-char ()
  (interactive)
  (foo-forward-char t))

(defun foo-next-line (&optional back)
  (interactive)
  (let ((olinenum (current-virtual-line-number)))
    (loop
      (if (and (next-virtual-line (if back -1 1))
	       (not (if back (bobp) (eobp))))
	  (return t)
	(let ((ogoal (goal-column)))
	  (goto-char (if back (point-min) (point-max)))
	  (unless (foo-forward-char back)
	    (return nil))
	  (unless (= olinenum (current-virtual-line-number))
	    (goto-virtual-column ogoal)
	    (set-goal-column ogoal)
	    (return t)))))))

(defun foo-previous-line ()
  (interactive)
  (foo-next-line t))

(defun foo-mode (&optional (arg nil sv))
  (interactive "p")
  (ed::toggle-mode 'foo-mode arg sv)
  (cond (foo-mode
	 (local-set-key #\Left 'foo-backward-char)
	 (local-set-key #\Right 'foo-forward-char)
	 (local-set-key #\Up 'foo-previous-line)
	 (local-set-key #\Down 'foo-next-line)
	 (scan-buffer *foo-regexp* :reverse t :regexp t)
	 (narrow-to-region (point) (point))
	 (foo-forward-char))
	(t
	 (widen)
	 (local-unset-key #\Left)
	 (local-unset-key #\Right)
	 (local-unset-key #\Up)
	 (local-unset-key #\Down)
	 t)))

--
亀井哲弥(Tetsuya Kamei)
kamei@xxxxxxxxxxxx/JCA00343@xxxxxxxxxxx

Index Home