🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.editor.mule
Article #513

Re: outline-mode

#513
From: Naoyuki Iso
Date: Thu, 03 Jun 1999 00:00
263 lines
11234 bytes
ジャパンエナジーの磯と申します。
会社からで、newsにポストできるかどうか不明です。:-)

In article <7j1dh7$65d$2@news2.na.rim.or.jp> SUZUKI Hitoshi <suzuki-h@mail.ne.jp> writes:
> 先日,outline-modeなるものがあることを知り,試してみたところ非常に便利
> で,サクサク使えるよう練習しているところです.

私もoutline-mode 愛用者です。

> しかし,自分が文章書くときの習慣として,
~ 省略 ~
> これで一応,アスタリスク・数字の双方を見出しの記号として認識してくれる
> ようにはなったのですが,レベルを文字列の長さで判断しているようで,前述
> の書き方では,思うようなアウトラインの展開をしません.
> 
> アスタリスクを全部一つにしておけば,なんとか使えるような状態にはなりま
> すが,できるなら数字の行頭記号の部分は,アスタリスクの下位として認識さ
> せることはできないでしょうか.
> 
> また,outline-mode以外に,こういったことが達成できるモードがあったなら,
> 紹介していただけたらと思います.

鈴木さんのいいたいことがいまいちわかっていないのですが...
以前、outlineのindex-headerを、リーガルスタイルのナンバリングに変換し
てくれるコマンドがあるとうれしいなぁと思い、いろいろ探したことがありま
す。探し方が悪かったのかもしれませんが、そういうやつを見つけることがで
きませんでした。

そこで、outline-modeをちょっと拡張してライブラリを作りました。へたくそ
なコーディングですが、よかったら使ってみて下さい。pathの通ったディレク
トリに置いて、.emacsに
(autoload 'outline-mode "outline-number" nil t)
と書けば使えるようになります。
##  使い方がわかるように、今回コメントを加えてみました。

このライブラリをロードした後は、C-r、C-v で *とリーガルスタイルのナン
バーを相互変換できるようにしてあります。

では。

------8<--------------------------------------------------------------
;; outline-number.el --- additional outline mode commands for Emacs
;; Auther:   Naoyuki Iso <iso@j-energy.co.jp>
;; Modified: "1999/06/03 12:15:36"  v 1.1

;;; Commentary:

;; このライブラリを使うと、outline-modeのHeader indexにリーガルスタイルのナンバ
;; リングを施せるようになります。
;;
;; outline-reset-index       Header indexを数字付きのindexに変更します。
;; outline-reset-index-char  Header indexを "*" に変更します。

;; また、hide entryした時に空行が残るというオリジナルのoutline-modeの仕様を、強
;; 引に変更することができます。(一度に見渡せる範囲が広くなるでしょ)
;;
;; outline-leave-line-togle  hide entry時に、heading前の空行を残さないようにしま
;;                           す。トグルスイッチになっています。
;;                           (setq outline-num-hide-blank-line t)でもオンになり
;;                           ます。

;; outline.elに定義されている次の関数は上書きされます。
;; outline-level, outline-next-preface, outline-end-of-subtree, show-children

;; このライブラリは、Mule 2.3 (Emacs 19.28.1)をターゲットにして作っています。もっ
;; と言うとmule for win32 です。オリジナルの outline.el の動きや変数に相当依存し
;; ているので、emacsのバージョンが違うと動かなくなる可能性大です。

;; outline-mode を呼んだ時に、自動的にこのライブラリもロードするには、このファイ
;; ルをload-pathの通ったディレクトリに置いた上で、.emacsファイルに、次のように記
;; 述して下さい。
;;
;; (autoload 'outline-mode "outline-number" nil t)

(require 'outline)

(defvar outline-num-index-sep ".")       ; ex   1.2.3
                                         ;       ^ ^    ここのことです
(defvar outline-num-heading-sep "  ")    ; ex   1.2.4  hogehoge
                                         ;           ^^ ここのことです
(defvar outline-num-regexp
  (concat " *[0-9]+\\(\\" outline-num-index-sep "[0-9]+\\)*" outline-num-heading-sep))
(setq outline-regexp (concat outline-regexp "\\|[*]+"))
(setq outline-regexp-org outline-regexp)
(setq outline-regexp (concat outline-regexp "\\|" outline-num-regexp))

(defvar outline-num-hide-blank-line nil)

(define-key outline-mode-prefix-map "\C-r" 'outline-reset-index)
(define-key outline-mode-prefix-map "\C-v" 'outline-reset-index-char)

(define-key outline-mode-menu-bar-map [headings outline-reset-index-char]
  '("Reset Index(chr)" . outline-reset-index-char))
(define-key outline-mode-menu-bar-map [headings outline-reset-index]
  '("Reset Index(num)" . outline-reset-index))

(defun connect-paragraph (&optional fill-prefix-tmp)
  (interactive)
  (let ((fill-column-org fill-column)
	(fill-prefix-org fill-prefix))
    (setq fill-column 100000)
    (if (not (null fill-prefix-tmp))
	(setq fill-prefix fill-prefix-tmp))
    (fill-paragraph t)
    (setq fill-column fill-column-org)
    (setq fill-prefix fill-prefix-org))
  )

(defun string-match-count (sep str)
  (let ((n nil)
        (cnt 0))
    (while (setq n (string-match sep str n))
      (setq cnt (1+ cnt))
      (setq n (1+ n)))
    cnt))

(defun outline-level ()
  (save-excursion
    (if (looking-at outline-regexp-org)
        (- (match-end 0) (match-beginning 0))
      (looking-at outline-num-regexp)
      (1+ (string-match-count (concat "\\" outline-num-index-sep) (match-string 0)))
      )))

(defun outline-reset-index ()
  "Header indexを数字付きのindexに変換します。"
  (interactive)
  (save-excursion
    (bob-insert-newline 1)
    (let ((index-array [0 1 2 3 4 5 6 7 8 9 10])  ; とりあえず 10レベルまで
          (pre-level 0)
          (cur-level 0))
      (fillarray index-array 0)
      (while (outline-next-heading)
        (if (> (setq cur-level (outline-level)) 10)
            (setq cur-level 10))        
        (aset index-array cur-level (1+ (aref index-array cur-level)))
        (let ((i pre-level))
          (while (> i cur-level)
            (aset index-array i 0)
            (setq i (1- i))))
        (let ((index-text (number-to-string(aref index-array 1)))
              (i 2))
          (while (<= i cur-level)
            (setq index-text
                  (concat index-text outline-num-index-sep
                          (number-to-string(aref index-array i))))
            (setq i (1+ i)))
          (setq index-text (concat index-text outline-num-heading-sep))
          (looking-at
           (concat "\\(" outline-regexp-org "\\)*\\(" outline-num-regexp "\\)*" ))
          (replace-match index-text))
        (setq pre-level cur-level)))
    (bob-insert-newline -1)))

(defun outline-reset-index-char ()
  "Header indexを * に変換します。"
  (interactive)
  (save-excursion
    (bob-insert-newline 1)
    (let ((index-text))
      (while (outline-next-heading)
        (setq index-text (make-string (outline-level) ?* ))
        (looking-at
         (concat "\\(" outline-regexp-org "\\)*\\(" outline-num-regexp "\\)*" ))
        (replace-match index-text)))
    (bob-insert-newline -1)))

(defun bob-insert-newline (arg)
  (beginning-of-buffer)
  (save-excursion
    (if (> arg 0) (newline arg)
      (kill-line (- arg)))))

(defun outline-hide-blank-line-togle (&optional arg)
  "hide entry する場合に、heading前の空行を残さないようにします。
残す/残さない のトグルスイッチになっています。"
  (interactive "P")
  (setq outline-num-hide-blank-line
        (if (null arg)
            (not outline-num-hide-blank-line)
          t)))

;; using hilit19
(hilit-set-mode-patterns
 'outline-mode
 (append
  '(("[\t]+" nil black/gray90))
  (list (cons
         (concat "^\\(" outline-regexp "\\)[^\n\^M]*" )
         '(nil blue-underline)))))

;;; re-defun s
(defun outline-next-preface ()
  "Skip forward to just before the next heading line.
If there's no following heading line, stop before the newline
at the end of the buffer."
  (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
                         nil 'move)
      (goto-char (match-beginning 0)))
  (if (not outline-num-hide-blank-line)
      (if (memq (preceding-char) '(?\n ?\^M))
          (forward-char -1))) )

(defun outline-end-of-subtree ()
  (outline-back-to-heading)
  (let ((opoint (point))
        (first t)
        (level (funcall outline-level)))
    (while (and (not (eobp))
                (or first (> (funcall outline-level) level)))
      (setq first nil)
      (outline-next-heading))
    (if (and (not (eobp))
             (memq (preceding-char) '(?\n ?\^M)))
        (progn
          ;; Go to end of line before heading
          (forward-char -1)
          (if (not outline-num-hide-blank-line)
              (if (memq (preceding-char) '(?\n ?\^M))
                  ;; leave blank line before heading
                  (forward-char -1)))))) )

(defun show-children (&optional level)
  "Show all direct subheadings of this heading.
Prefix arg LEVEL is how many levels below the current level should be shown.
Default is enough to cause the following heading to appear."
  (interactive "P")
  (setq level
        (if level (prefix-numeric-value level)
          (save-excursion
            (outline-back-to-heading)
            (let ((start-level (funcall outline-level)))
              (outline-next-heading)
              (if (eobp)
                  1
                (max 1 (- (funcall outline-level) start-level)))))))
  (save-excursion
    (save-restriction
      (outline-back-to-heading)
      (setq level (+ level (funcall outline-level)))
      (narrow-to-region (point)
                        (progn (outline-end-of-subtree)
                               (if (eobp) (point-max) (1+ (point)))))
      (goto-char (point-min))
      (while (and (not (eobp))
                  (progn
                    (outline-next-heading)
                    (not (eobp))))
        (if (<= (funcall outline-level) level)
            (save-excursion
              (outline-flag-region (save-excursion
                                     (forward-char -1)
                                     (if (not outline-num-hide-blank-line)
                                         (if (memq (preceding-char) '(?\n ?\^M))
                                             (forward-char -1)) )
                                     (point))
                                   (progn (outline-end-of-heading) (point))
                                   ?\n)))))))

(provide 'outline-number)

;;; outline-number.el ends here
Technical Details
Message-ID: <ISO.99Jun03182010@PCA2108.hq.j-energy.co.jp>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7j1dh7$65d$2@news2.na.rim.or.jp>

Show Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS
X-Google-Thread: 10eba4,11005f6b9ea894ff
X-Google-Attributes: gid10eba4,public
From: iso@PCA2108.hq.j-energy.co.jp (Naoyuki Iso)
Subject: Re: outline-mode
Date: 1999/06/03
Message-ID: <ISO.99Jun03182010@PCA2108.hq.j-energy.co.jp>
X-Deja-AN: 486834710
Distribution: inet
References: <7j1dh7$65d$2@news2.na.rim.or.jp>
Content-Type: text/plain; charset=ISO-2022-JP
Organization: Japan Energy co. Infomation System Dept.
Mime-Version: 1.0 (generated by tm-edit 7.106)
Newsgroups: fj.editor.mule