inline image in markdown-mode

f:id:syohex:20160405142811g:plain

github.com

I have implemented inline image feature in markdown-mode. You can see image file in buffer by M-x markdown-toggle-inline-images command. This command is bound to C-c C-i C-t by default. You cannot use this feature in no GUI Emacs like emacs -nw.

Please report us via github issues if you have any issues.

Thanks for using markdown-mode.

vc-mode-line

最近知ったのですが, vc-modeが mode-lineに表示している情報(VCS+branch名: gitリポジトリであれば Gitとmasterを表示)はファイルが前のコミットから変更されている場合と されていない場合で異なります. わかりづらいですが, 変更がない場合 VCSとブランチ名のサパレータが -, 変更があった場合は :になります.

変更なし

f:id:syohex:20160210175831p:plain

変更あり

f:id:syohex:20160210175839p:plain

見づらい・わかりづらい

上記で示した通り, 見づらいし, わかりづらいんですが, 有用な情報だなと思ったので, 別情報を表示することにしてみました.

現在のバッファの変更 hunk数の表示

現在お試し中. git-gutterユーザ限定ではあるが, (git-gutter:buffer-hunks)という APIで現在の hunk数を取得している. 変更内容にもよるが, 多すぎるとそろそろコミットしておかないとなぁという気分になれるのでなかなかよい.

f:id:syohex:20160210183017p:plain

(defvar my/vc-mode-line
  '(:propertize
    (:eval (let* ((backend (symbol-name (vc-backend (buffer-file-name))))
                  (branch (substring-no-properties vc-mode (+ (length backend) 2)))
                  (state (if (bound-and-true-p git-gutter-mode)
                             (cl-case (vc-state (buffer-file-name))
                               (edited
                                (format ":%d" (git-gutter:buffer-hunks)))
                               (otherwise ""))
                           "")))
             (concat "(" branch state ")"))))
  "Mode line format for VC Mode.")
(put 'my/vc-mode-line 'risky-local-variable t)

(setq-default mode-line-format
                '("%e"
                  mode-line-front-space
                  mode-line-mule-info
                  mode-line-client
                  mode-line-modified
                  mode-line-remote
                  mode-line-frame-identification
                  mode-line-buffer-identification " " mode-line-position
                  (vc-mode my/vc-mode-line)
                  " "
                  mode-line-modes mode-line-misc-info mode-line-end-spaces))

現在のバッファの変更状態を表示

(git-gutter:statistic) APIを使ってみた場合(上記の設定にはめ込んでみてください). 戻り地は dot-listで carが追加行数, cdrが削除行数となっている. 具体的すぎるように思えるので保留.

f:id:syohex:20160210190348p:plain

Emacs Lispで socketプログラミング

http://mattn.kaoriya.net/software/vim/20160129114716.htm

Emacsが socket使えることは知っていたが, 使ったことがなかったので書いてみました.

コード

(require 'json)

(let ((proc (open-network-stream "test" (get-buffer-create "*test*") "localhost" 8888)))
  (set-process-filter proc (lambda (proc output)
                             (let ((resp (json-read-from-string output)))
                              (message "ただ今: %s" (aref resp 1)))))
  (process-send-string proc (json-encode [1 "GET"]))
  (process-send-eof proc))

open-network-streamは processオブジェクトを返します. 後は start-processみたく扱ってやればよいようです. 非同期です. set-process-filterで callback関数を指定します. process-send-stringでサーバに sendします.

サーバプログラムは上記の記事に載っているものを使っています. 無駄な処理がいくらか含まれてしまっていますが...

結果

サーバを動かし, 上記の式を評価すると以下のようになります.

f:id:syohex:20160131120830g:plain

Emacsで手動スクレイピング

元ネタ

http://qiita.com/muran001/items/7a76a1c70aa12ed68cb6

はてぶのページからリンクを取得する

Vimほど楽ではない気がするが一応

M-x browse-url-emacs [RET] http://b.hatena.ne.jp/ctop/it
;; windowを切り替え, read-only-modeを解除
M-x replace-regexp [RET] >< [RET] >改行< ; 改行は C-r C-jで入力
M-x replace-regexp [RET] ^\s-+ [RET] ; 行頭の空白削除
M-x delete-non-matching-lines [RET] <a [RET]
M-x replace-regexp [RET] ^.*href="\([^"]+\)".*$ [RET] \1

Gifは割愛.

解説

データ取得

M-x browse-url-emacsで直に HTMLファイルを開けます

HTML整形

replace-regexpコマンドで頑張る

M-x replace-regexp [RET] >< [RET] >改行< ; 改行は C-r C-jで入力
M-x replace-regexp [RET] ^\s-+ [RET] ; 行頭の空白削除

フィルタリング

delete-non-matching-linesで指定した正規表現にマッチしない行を削除できる. その逆は delete-matching-linesでマッチした行を残す.

M-x delete-non-matching-lines [RET] <a [RET]

データの整形

やはり replace-regexpで頑張る

M-x replace-regexp [RET] ^.*href="\([^"]+\)".*$ [RET] \1 ; リンクの中身のみ取得

おまけ

正規表現をイメージするときは re-builderも良いかもしれない. 以下は reb-re-syntax'stringのときのスクリーンショットです.

f:id:syohex:20160111215649p:plain

2015年を振り返る

f:id:syohex:20151231214528p:plain

f:id:syohex:20151231214608p:plain

f:id:syohex:20151231214634p:plain

ある日, 古い Emacsパッケージを使おうとしたとき全然動かなくて, 動くための PRを送ったんですが, そのとき他のも動くのかなと古いやつを片っ端からダウンロードし, 試してみたらいろいろ問題が見つかり PRしまくっていました. それで妙に草が生えてしまっています. それに伴い githubリポジトリ数も 1000を超えてしまうということになってしまいました.

あとはひたすらメンテナンスですかね. 今年は新しい物を作らなすぎたと思います. 最後の方は Emacs dynamic moduleのテストのためにあれこれ書いてみましたが, どれも中途半端な感じになってしまいました. 来年は新しいものを作れるようにしたいですね.

f:id:syohex:20151231215225p:plain

f:id:syohex:20151231215308p:plain

自分のやる気のなさが原因としか言えませんが, 早い内になんとかしたいです.

f:id:syohex:20151231215606p:plain

f:id:syohex:20151231215618p:plain

参考