| | 97 | |
| | 98 | ;; シンボル及び関数定義の操作 |
| | 99 | |
| | 100 | (defun func (x) (* x x)) ; func |
| | 101 | (symbol-function 'func) ; (lambda (x) (* x x)) |
| | 102 | (byte-compile 'func) ; #[(x) "\211_\207" [x] 2] |
| | 103 | (symbol-function 'func) ; #[(x) "\211_\207" [x] 2] |
| | 104 | |
| | 105 | (defalias 'atomp 'atom) ; atom |
| | 106 | (atomp '(1 2)) ; nil |
| | 107 | (atomp "123") ; t |
| | 108 | |
| | 109 | ;; 動作が良く分からないので後回し |
| | 110 | ;; (let ((somefunc1-b (symbol-function 'somefunc1)) |
| | 111 | ;; (somefunc2-b (symbol-function 'somefunc2))) |
| | 112 | ;; (fset 'somefunc1 'ignore) |
| | 113 | ;; (fset 'somefunc2 'ignore) |
| | 114 | ;; (unwind-protect |
| | 115 | ;; (progn (+ 1 2)) |
| | 116 | ;; (fset 'somefunc1 somefunc1-b) |
| | 117 | ;; (fset 'somefunc2 somefunc2-b))) |
| | 118 | |
| | 119 | (setq x 10) ; 10 |
| | 120 | (intern (concat "my-symbol-" (number-to-string x))) ; my-symbol-10 |
| | 121 | (intern-soft "my-symbol-10") ; my-symbol-10 |
| | 122 | (intern-soft "my-symbol-11") ; nil |
| | 123 | (unintern "my-symbol-10") ; t |
| | 124 | |
| | 125 | ;; アドバイスの概要 |
| | 126 | |
| | 127 | (defadvice list-buffers (after pop-to-buffer-list) |
| | 128 | (pop-to-buffer "*Buffer List*")) ; list-buffers |
| | 129 | (ad-activate 'list-buffers) ; list-buffers |
| | 130 | |
| | 131 | ;; アドバイスの定義 |
| | 132 | |
| | 133 | (defun triple (x) (* x 3)) ; triple |
| | 134 | (defadvice triple (before before-triple) |
| | 135 | (princ (format "before\n"))) ; triple |
| | 136 | (defadvice triple (after after-triple) |
| | 137 | (princ (format "after\n"))) ; triple |
| | 138 | (defadvice triple (around around-triple) |
| | 139 | (princ (format "around-before\n")) |
| | 140 | ad-do-it |
| | 141 | (princ (format "around-after\n"))) ; triple |
| | 142 | (ad-activate 'triple) ; triple |
| | 143 | |
| | 144 | (triple 3) |
| | 145 | ;before |
| | 146 | ;around-before |
| | 147 | ;around-after |
| | 148 | ;after |
| | 149 | ;9 |
| | 150 | |
| | 151 | ;; アドバイスの活性化と有効化 |
| | 152 | |
| | 153 | (ad-disable-advice 'triple 'around 'around-triple) ; nil |
| | 154 | (ad-activate 'triple) ; triple |
| | 155 | (triple 7) |
| | 156 | ;before |
| | 157 | ;after |
| | 158 | ;21 |
| | 159 | |
| | 160 | (ad-enable-advice 'triple 'around 'around-triple) ; nil |
| | 161 | (ad-activate 'triple) ; triple |
| | 162 | (triple 7) |
| | 163 | ;before |
| | 164 | ;around-before |
| | 165 | ;around-after |
| | 166 | ;after |
| | 167 | ;21 |
| | 168 | |
| | 169 | (ad-deactivate 'triple) ; triple |
| | 170 | (triple 7) ; 21 |
| | 171 | |
| | 172 | ;; 引数及び返却値の操作 |
| | 173 | |
| | 174 | (defun sample (x y z) (list x y z)) ; sample |
| | 175 | (defadvice sample (before before-sample1) |
| | 176 | (princ (format "arg 1: %s\n" |
| | 177 | (ad-get-arg 1)))) ; sample |
| | 178 | (defadvice sample (before before-sample2) |
| | 179 | (princ (format "args 1: %s\n" |
| | 180 | (ad-get-args 1)))) ; sample |
| | 181 | (defadvice sample (before before-sample3) |
| | 182 | (ad-set-arg 0 "arg 0")) ; sample |
| | 183 | (defadvice sample (before before-sample4) |
| | 184 | (ad-set-args 1 '("arg 1" "arg 2"))) ; sample |
| | 185 | (defadvice sample (around around-sample) |
| | 186 | (princ (format "around begin:\n")) |
| | 187 | ad-do-it |
| | 188 | (princ (format "around end:\n"))) ; sample |
| | 189 | (defadvice sample (after after-sample) |
| | 190 | (princ (format "%s\n" |
| | 191 | ad-return-value)) |
| | 192 | (setq ad-return-value '(1 2 3))) ; sample |
| | 193 | (ad-activate 'sample) ; sample |
| | 194 | |
| | 195 | (sample 4 5 6) |
| | 196 | ;args 1: (arg 1 arg 2) |
| | 197 | ;arg 1: arg 1 |
| | 198 | ;around begin: |
| | 199 | ;around end: |
| | 200 | ;(arg 0 arg 1 arg 2) |
| | 201 | ;(1 2 3) |
| | 202 | |
| | 203 | ;; ファイルロードの概要 |
| | 204 | |
| | 205 | (setq load-path (cons "~/mylisp" load-path)) |
| | 206 | (setq load-path (append (list "~/mylisp" "/opt/lisp") load-path)) |