auto-complete.el 1.0aでlambdaで定義したコマンドが使えない
2009-11-20 追記
以下の変更は、 322dcb5a で本家にmergeされました。<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
auto-complete.elのversionを 1.0a(http://github.com/m2ym/auto-complete)に上げたのですが、
(global-set-key (kbd "=") (lambda () (interactive) (insert "=")))上のようにlambdaで定義されているコマンドを実行すると、エラーが出るようになってしまいました。
軽く追ってみたところ、ac-trigger-command-pのなかのsymbol-nameにlistが渡るのが原因みたいです。具体的には、以下のテストが通りません。
(dont-compile (when (fboundp 'expectations) (expectations (desc "ac-trigger-command-p retums nil if command is lambda") (expect t (let ((command-fn (lambda () (interactive) "hi!"))) (when (commandp command-fn) t))) (expect nil (let ((command-fn (lambda () (interactive) "hi!"))) (ac-trigger-command-p command-fn))))))コマンドを返す関数( (lambda () (interactive) ...) を返す関数)をつかってコマンドを定義するとこのような問題がでるかも、と思いました。
稚拙、http://github.com/imakado/emacs-smartchr でもこの方法でコマンドを定義しています。とりあえずの回避策として、ac-trigger-command-pにlistで定義されたコマンドが渡って来た場合に、nilを返すようにしてみました。
http://github.com/imakado/auto-complete
githubにコードがあったので、forkしてpushしました。実は久しぶりにauto-complete.elのバージョン上げたのですが、凄く便利になっていて感激しました。(incf m2ym )
k1LoWさんの "動かないと業務に支障がでる" 発言にも納得です。
anything-projectの候補にディレクトリが含まれないようにする
(setq ap:project-files-filters (list (lambda (files) (remove-if 'file-directory-p files))))
最新の anything-project.el だと上のように書いておけばファイルのみが対象になります。
ランダムに一つのROWをとってくる
package App::Schema::Table::Hoge; use strict; use warnings; use base qw/DBIx::Class::ResultSet/; sub get_random_row { my ($self) = @_; my @ids = $self->search( {}, { select => [ qw/ id / ], } )->get_column('id')->all; my $id = $ids[ int( rand( scalar @ids ) ) ]; $self->find($id); } 1;
こんな感じかなあ。
SELECT * FROM hoge ORDER BY rand() LIMIT 1;
auto-complete.el の ac-source-words-in-buffer の候補に日本語を含む単語が含まれないようにする
(require 'cl) (require 'auto-complete) (defadvice ac-candidate-words-in-buffer (after remove-word-contain-japanese activate) (let ((contain-japanese (lambda (s) (string-match (rx (category japanese)) s)))) (setq ad-return-value (remove-if contain-japanese ad-return-value))))
以下、テスト
(defmacro my-with-php-buffer (s &rest body) (declare (indent 1)) `(with-temp-buffer (php-mode) (insert ,s) (goto-char (point-min)) (when (re-search-forward (rx "`!!'") nil t) (replace-match "")) (progn ,@body))) (expectations (expect '("aaああああ" "aabbcc") (my-with-php-buffer "aaああああ `!!' \n aabbcc" (let ((ac-target "aa") (ac-point (point)) (ac-limit 20)) (ad-disable-advice 'ac-candidate-words-in-buffer 'after 'remove-word-contain-japanese) (ad-activate 'ac-candidate-words-in-buffer) (ac-candidate-words-in-buffer)))) (expect '("aabbcc") (my-with-php-buffer "aaああああ `!!' \n aabbcc" (let ((ac-target "aa") (ac-point (point)) (ac-limit 20)) (ad-enable-advice 'ac-candidate-words-in-buffer 'after 'remove-word-contain-japanese) (ad-activate 'ac-candidate-words-in-buffer) (ac-candidate-words-in-buffer)))))
Executing expectations in nil... 2 expectations, 0 failures, 0 errors Expectations finished at Thu Aug 13 11:34:44 2009 1 :OK 2 :OK 2 expectations, 0 failures, 0 errors Expectations finished at Thu Aug 13 11:34:44 2009
php-modeなのは特に意味ないです。
symfony.el始めました。
一昨日くらいからsymfony.elを作り始めました。
rails.el や rinari.el, symfony.vim とか見ながら作ってます。
コードはgithub上にあります。
http://github.com/imakado/emacs-symfony/tree/master
絶賛開発中でございます。
Installation
`anything.el' http://www.emacswiki.org/emacs/anything.el `anything-match-plugin.el' http://www.emacswiki.org/emacs/anything-match-plugin.el `anything-project.el' http://github.com/imakado/emacs-symfony/tree/master `symfony.el' http://github.com/imakado/emacs-symfony/tree/master
いれて、
(require 'symfony)
で行けると思います。
Commands
今のところあるコマンド
;;(loop for (key . command) in (sf:command-infomation) ;; do (insert "["key"]" " " command "\n")) [C-c C-n] sf-cmd:relative-files [C-c C-p] sf-cmd:primary-switch [C-c <down>] sf-cmd:relative-files [C-c <up>] sf-cmd:primary-switch [C-c C-c l] sf-cmd:open-log-file [C-c C-c g T] sf-cmd:test-files [C-c C-c g a] sf-cmd:action-files [C-c C-c g h] sf-cmd:helper-files [C-c C-c g m] sf-cmd:model-files [C-c C-c g t] sf-cmd:template-files
conspとlistpの違い
(equal t (consp nil)) ;;=> nil (equal t (listp nil)) ;;=> t
いままで iモードID(guid, 個体識別番号)は大文字・小文字の区別ありなことを意識していなかった
いわゆる、かんたんログインと呼ばれる認証方法をドコモ端末で実装するときにつかわれていると思われるiモードIDですが、大文字・小文字の区別あり、だということを今日初めて知りました。
以下、問題になった部分の最小構成。かんたんログインの是非はいったん置いておきます。
CREATE TABLE `user` ( id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, mobile_id VARCHAR(255) NOT NULL, PRIMARY KEY(id), UNIQUE INDEX user_mobile_id(mobile_id) );
INSERT INTO `user` (mobile_id) VALUES('xx0000x'); -- => Query OK, 1 row affected (0.06 sec) INSERT INTO `user` (mobile_id) VALUES('xx0000X'); -- => ERROR 1062 (23000): Duplicate entry 'xx0000X' for key 2
case in sensitive !!
ALTER TABLE `user` MODIFY COLUMN mobile_id VARCHAR(255) BINARY NOT NULL;
して、
INSERT INTO `user` (mobile_id) VALUES('xx0000X'); -- => Query OK, 1 row affected (0.00 sec) SELECT * FROM user; -- => -- +----+-----------+ -- | id | mobile_id | -- +----+-----------+ -- | 1 | xx0000x | -- | 2 | xx0000X | -- +----+-----------+ -- 2 rows in set (0.00 sec)
iモードID xx0000x でアクセスして来た人に xx0000X の人のページを表示してしまう可能性があった。
そのうちおこる可能性はあったなあ。気をつけないと。勉強になりました。
2009/08/06修正
一回目のインサート 'xx0000X' -> 'xx0000x'