Source of Nothingness - interactive

* Menu

About | Profile | まとめ | オリジナル | xyzzy | あんてな | | buzz

* 2008-03-09 :

(ReadMore...)

* xyzzy lisp :

こんなのを用意してみた。
cronがちゃんと働けば、一日3回更新チェックをするはず。

(defun ni::add-site-from-raido ()
  (interactive)
  (ni::load-site-data)
  (mapcar
   (lambda (x) (ignore-errors (ni::site-add x)))
   (set-difference
    (let ((stream (ni::http-get-url "http://raido.sakura.ne.jp/southly/lisp/ni/ni-status.txt")))
      (do* ((line (read-line stream nil nil) (read-line stream nil nil))
            (r nil))
          ((not line) (nreverse r))
        (unless (string-matchp "^\\(4[0-9][0-9]\\|NIL\\)" line)
          (push (second (split-string line " ")) r))))
    (mapcar (lambda (x) (cdr (assoc "src" x :test #'equal))) ni::*site-data*)
    :test #'string=)))
(define-key ni::*site-map* #\N 'ni::add-site-from-raido)

* xyzzy lisp : ミニバッファの入力にエスケープシーケンス

interactive指定子を作っちゃえば楽に置き換えられるんじゃね?
ってことで、こんな。
(in-package "editor")
(defun interactive-read-string-with-escape-sequence (prompt default history title)
  (list (decode-escape-sequence (read-string prompt :default default :history history) nil)))
(pushnew '(#\w . interactive-read-string-with-escape-sequence)
	 *interactive-specifier-alist* :test #'equal)
(defun interactive-read-regexp-with-escape-sequence (prompt default history title)
  (list (decode-escape-sequence (read-string prompt :default default :history history) t)))
(pushnew '(#\W . interactive-read-regexp-with-escape-sequence)
	 *interactive-specifier-alist* :test #'equal)

;; こんな感じで使う
;; 文字列
(defun search-forward-wes (pattern &optional noerror)
  (interactive "wSearch forward: "
    :default0 *last-search-string* :history0 'search)
  (search-command pattern nil nil (interactive-p) noerror))
;; 正規表現
(defun re-search-forward-wes (regexp &optional noerror)
  (interactive "WRe-search forward: "
    :default0 *last-search-regexp* :history0 'search)
  (search-command regexp nil t (interactive-p) noerror))
(export '(search-forward-wes re-search-forward-wes))
(in-package "user")

* memo :

なんか最近Lisp書いてないので書き捨ててみた
C++用
(defun foo ()
  (interactive)
  (let ((l nil))
    (save-excursion
      (goto-char (point-min))
      (while (scan-buffer "\\bstd::\\(\\sw\\|\\s_\\)+" :regexp t :no-dup t)
        (pushnew (match-string 0) l :test #'string=)))
    (dolist (x l)
      (insert (format nil "using ~a;~%" x)))))

(defun bar ()
  (interactive)
  (perform-replace "\\bstd::\\(\\(\\sw\\|\\s_\\)+\\)" "\\1" nil t nil nil))

* Scrapbook : Webデザインとグラフィックの総合情報サイト - MdN Interactive - Webデザイン超基本のお作法50選

 http://www.mdn.co.jp/content/view/1619/104/

* editorパッケージのbuiltin関数

以下で調べて652個
(let ((count 0))
  (do-symbols (sym (find-package "editor") (format t "~%count: ~d~%" count))
    (when (and (not (find-symbol (symbol-name sym) "lisp"))
               (fboundp sym)
               (si:*builtin-function-p (symbol-function sym)))
      (format t "~a~%" sym)
      (incf count))))
(ReadMore...)

* 適当すぎる

(ReadMore...)

* xyzzy lisp : clone-buffer

とりあえずこんなところか。
主だったところはsession.lから。
outline-tree2をバッファバーの代わりにしつつ、rename-bufferを良く使う人向け。
もしくは*compilation*バッファとかでうっかりそのまま編集して、undoができず残念な思いをする人向け。
(defun clone-buffer (buffer-name &optional (buffer (selected-buffer)))
  (interactive "sClone Buffer: ")
  (let ((major buffer-mode)
        (minor (mapcan #'(lambda (mode)
                           (let ((var (and (consp mode) (car mode))))
                             (and (symbolp var)
                                  (boundp var)
                                  (symbol-value var)
                                  (list var))))
                       *minor-mode-alist*))
        (locals (mapcar #'(lambda (var)
                            (and (symbolp var)
                                 (local-variable-p var)
                                 (cons var (symbol-value var))))
                        *buffer-info-variable-list*))
        (point (point)))
    (set-buffer (create-new-buffer buffer-name))
    (insert-buffer buffer)
    (funcall major)
    (mapc #'(lambda (f) (and (fboundp f) (funcall f))) minor)
    (mapc #'(lambda (x)
              (when (and (car x) (symbolp (car x)))
                (make-local-variable (car x))
                (set (car x) (cdr x))))
          locals)
    (goto-char point)))

メモ:
undo情報をそっくり写せるとうれしいかも。
(ReadMore...)

* xyzzy lisp : insert-include

てきとー
(defun insert-include (file &optional cwd)
  (interactive "lHeader: " :default0 (merge-pathnames "*.h"))
  (unless cwd
    (if (get-buffer-file-name)
        (setq cwd (directory-namestring (get-buffer-file-name)))
      (return-from insert-include nil)))
  (if (consp file)
      (dolist (f file)
        (insert-include f cwd))
    (insert (format nil "~%#include \"~A\"" (substitute-string file (regexp-quote cwd) "" :case-fold t)))))

* xyzzy lisp : へなちょこ補完その3

絞込み
(ReadMore...)

* xyzzy lisp : へなちょこ補完その2

候補の絞込みしていなかったのを修正。
(ReadMore...)

* xyzzy lisp : へなちょこ補完

C/C++とかJavaとかのメンバをdabbrevライクに補完
てきとー
(ReadMore...)

* xyzzy lisp : なんとなく

(defun sort-by-column-region (beg end &optional (f #'<))
  (interactive "*r")
  (let ((lines (split-string (buffer-substring beg end) #\LFD t))
        (pred #'(lambda (x y) (funcall f (length x) (length y)))))
    (setq lines (sort lines pred))
    (goto-char (min beg end))
    (delete-region beg end)
    (insert (format nil "~{~A~%~}" lines))))

* xyzzy lisp : 位置とサイズの操作

また勢いだけで使いそうに無いものを作ってしまった。
(ReadMore...)

*

(defun delete-blank-lines-region (start end)
  (interactive "*r")
  (save-restriction
    (narrow-to-region start end)
    (save-excursion
      (goto-char (point-min))
      (while (and (scan-buffer "^$" :no-dup t :regexp t)
                  (not (eobp)))
        (delete-blank-lines)))))