LoginSignup
7
6

More than 5 years have passed since last update.

[CentOS7] emacs24にemacs-w3mインストール

Last updated at Posted at 2014-11-11

emacs-w3mとは

emacsからw3mを使ってウェブブラウジングを可能にするelパッケージ。
CentOS6までは標準リポジトリにw3mがあった気がするが7の標準リポジトリには見あたらなかったので手動でインストールする手順を書く。

手順

  • w3mをインストール
  • emacs-w3mをインストール
  • init.el設定

w3mをインストール

Cのガベージコレクションライブラリであるgcのヘッダが必要なのでインストールする。
幸いにもこれは標準リポジトリにあった。


% sudo yum install gc-devel

w3mのアーカイブをダウンロード、解凍、コンパイルの流れ。
http://sourceforge.net/projects/w3m/files/w3m/

% wget "http://sourceforge.net/projects/w3m/files/w3m/w3m-0.5.3/w3m-0.5.3.tar.gz/download" -O w3m.tar.gz
% tar zxvf w3m.tar.gz
% cd w3m-0.5.3/

順調に行くと思ったがmakeで普通にコンパイルしようとすると次のようなエラーを吐く。

In file included from html.h:10:0,
                 from fm.h:39,
                 from main.c:3:
istream.h:23:8: エラー: ‘struct file_handle’ の再定義です
 struct file_handle {
        ^
In file included from /usr/include/bits/fcntl.h:61:0,
                 from /usr/include/fcntl.h:35,
                 from istream.h:14,
                 from html.h:10,
                 from fm.h:39,
                 from main.c:3:
/usr/include/bits/fcntl-linux.h:300:8: 備考: 元々はここで定義されました
 struct file_handle
        ^
main.c: 関数 ‘main’ 内:
main.c:836:23: エラー: void の値が本来の意味通りに無視されませんでした
     orig_GC_warn_proc = GC_set_warn_proc(wrap_GC_warn_proc);
                       ^
main.c: 関数 ‘getChar’ 内:
main.c:2264:5: 警告: 互換性のないポインタ型から 1 番目の ‘wtf_parse1’ の引数に渡しています [デフォルトで有効]
     return wc_any_to_ucs(wtf_parse1(&p));
     ^
In file included from fm.h:44:0,
                 from main.c:3:
./libwc/wtf.h:71:19: 備考: expected ‘wc_uchar **’ but argument is of type ‘char **’
 extern wc_wchar_t wtf_parse1(wc_uchar **p);
                   ^
make: *** [main.o] エラー 1

あらま。これには大きく分けて2つの原因がある。
まず一つ目、エラーメッセージの1~25行目
どうやら構造体の名前が標準ライブラリの中のものと被ったらしい。
grepしてみるとこの通り。

% grep -rl file_handle *
istream.c:static void file_close(struct file_handle *handle);
istream.c:static int file_read(struct file_handle *handle, char *buf, int len);
istream.c:    stream->file.handle = New(struct file_handle);
istream.c:file_close(struct file_handle *handle)
istream.c:file_read(struct file_handle *handle, char *buf, int len)
istream.h:struct file_handle {
istream.h:    struct file_handle *handle;

ベンダプレフィックスの重要さを噛み締めながらコンパイルを通すために名前を一括置換した。
置換するソースはistream.cとistream.hの2つ。

sed -i -e "s/file_handle/w3m_file_handle/g" istream.?

そして二つ目の原因はgcライブラリのバージョンによる関数定義の差異。
変更した差分は次の通り。

--- main.c      2014-11-11 15:00:18.001209935 +0900
+++ main_fix.c      2014-11-11 15:03:38.718975774 +0900
@@ -311,7 +311,7 @@
            lock = 0;
        }
     }
-    else if (orig_GC_warn_proc)
+    else if (orig_GC_warn_proc = GC_get_warn_proc())
        orig_GC_warn_proc(msg, arg);
     else
        fprintf(stderr, msg, (unsigned long)arg);
@@ -833,7 +833,7 @@
     mySignal(SIGPIPE, SigPipe);
 #endif

-    orig_GC_warn_proc = GC_set_warn_proc(wrap_GC_warn_proc);
+    GC_set_warn_proc(wrap_GC_warn_proc);
     err_msg = Strnew();
     if (load_argc == 0) {
        /* no URL specified */

そして、コンパイル&インストール。

% ./configure
% sudo make && make install

emacs-w3mのインストール

w3mで少し手間どったがこちらは簡単。
emacs24ではM-x package-install w3mで一発。
ちなみにパッケージ管理はCask+palletの組み合わせが便利。

init.el設定

w3mの設定を追記する。

~/.emacs.d/init.el
;パスは読み替えて
(add-to-list 'load-path "~/path/to/emacs-w3m/")
(require 'w3m)
;検索エンジンにGoogleを登録
(eval-after-load "w3m-search"
                 '(add-to-list 'w3m-search-engine-alist
                               '("google" "https://encrypted.google.com/search?num=100&ie=utf-8&oe=utf-8&hl=ja&safe=off&filter=0&pws=0&complete=0&gbv=1&q=%s" utf-8)))
;デフォルトの検索エンジンをGoogleに設定
(setq w3m-search-default-engine "google")
;初期ページをGoogleトップに
(setq w3m-home-page "http://www.google.co.jp")
;cookieを使用
(setq w3m-use-cookies t)

追記

w3mのコンパイルでtputsがどうのこうのエラーを吐く場合はncurses-develをインスコすると解決すると思います。

% sudo yum install ncurses-devel
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6