Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/elisp/chm-view.el
987 views
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>EmacsWiki: chm-view.el</title><link rel="alternate" type="application/wiki" title="Edit this page" href="http://www.emacswiki.org/emacs?action=edit;id=chm-view.el" /><link type="text/css" rel="stylesheet" href="/emacs/wiki.css" /><meta name="robots" content="INDEX,FOLLOW" /><link rel="alternate" type="application/rss+xml" title="EmacsWiki" href="http://www.emacswiki.org/emacs?action=rss" /><link rel="alternate" type="application/rss+xml" title="EmacsWiki: chm-view.el" href="http://www.emacswiki.org/emacs?action=rss;rcidonly=chm-view.el" />
3
<link rel="alternate" type="application/rss+xml"
4
title="Emacs Wiki with page content"
5
href="http://www.emacswiki.org/emacs/full.rss" />
6
<link rel="alternate" type="application/rss+xml"
7
title="Emacs Wiki with page content and diff"
8
href="http://www.emacswiki.org/emacs/full-diff.rss" />
9
<link rel="alternate" type="application/rss+xml"
10
title="Emacs Wiki including minor differences"
11
href="http://www.emacswiki.org/emacs/minor-edits.rss" />
12
<link rel="alternate" type="application/rss+xml"
13
title="Changes for chm-view.el only"
14
href="http://www.emacswiki.org/emacs?action=rss;rcidonly=chm-view.el" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body class="http://www.emacswiki.org/emacs"><div class="header"><a class="logo" href="http://www.emacswiki.org/emacs/SiteMap"><img class="logo" src="/emacs_logo.png" alt="[Home]" /></a><span class="gotobar bar"><a class="local" href="http://www.emacswiki.org/emacs/SiteMap">SiteMap</a> <a class="local" href="http://www.emacswiki.org/emacs/Search">Search</a> <a class="local" href="http://www.emacswiki.org/emacs/ElispArea">ElispArea</a> <a class="local" href="http://www.emacswiki.org/emacs/HowTo">HowTo</a> <a class="local" href="http://www.emacswiki.org/emacs/RecentChanges">RecentChanges</a> <a class="local" href="http://www.emacswiki.org/emacs/News">News</a> <a class="local" href="http://www.emacswiki.org/emacs/Problems">Problems</a> <a class="local" href="http://www.emacswiki.org/emacs/Suggestions">Suggestions</a> </span>
15
<!-- Google CSE Search Box Begins -->
16
<form class="tiny" action="http://www.google.com/cse" id="searchbox_004774160799092323420:6-ff2s0o6yi"><p>
17
<input type="hidden" name="cx" value="004774160799092323420:6-ff2s0o6yi" />
18
<input type="text" name="q" size="25" />
19
<input type="submit" name="sa" value="Search" />
20
</p></form>
21
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_004774160799092323420%3A6-ff2s0o6yi"></script>
22
<!-- Google CSE Search Box Ends -->
23
<br /><span class="specialdays">Philippines, Independence Day, Russia, National Day</span><h1><a title="Click to search for references to this page" rel="nofollow" href="http://www.google.com/cse?cx=004774160799092323420:6-ff2s0o6yi&amp;q=%22chm-view.el%22">chm-view.el</a></h1></div><div class="wrapper"><div class="content browse"><p class="download"><a href="download/chm-view.el">Download</a></p><pre class="code"><span class="linecomment">;;; chm-view.el --- View CHM file.</span>
24
25
<span class="linecomment">;; Filename: chm-view.el</span>
26
<span class="linecomment">;; Description: View CHM file.</span>
27
<span class="linecomment">;; Author: Andy Stewart &lt;[email protected]&gt;</span>
28
<span class="linecomment">;; Maintainer: Andy Stewart &lt;[email protected]&gt;</span>
29
<span class="linecomment">;; Copyright (C) 2009, Andy Stewart, all rights reserved.</span>
30
<span class="linecomment">;; Created: 2009-01-28 21:35:26</span>
31
<span class="linecomment">;; Version: 0.2.2</span>
32
<span class="linecomment">;; Last-Updated: 2009-04-16 10:48:52</span>
33
<span class="linecomment">;; By: Andy Stewart</span>
34
<span class="linecomment">;; URL: http://www.emacswiki.org/emacs/download/chm-view.el</span>
35
<span class="linecomment">;; Keywords: chm, chm-view</span>
36
<span class="linecomment">;; Compatibility: GNU Emacs 23.0.60.1</span>
37
<span class="linecomment">;;</span>
38
<span class="linecomment">;; Features that might be required by this library:</span>
39
<span class="linecomment">;;</span>
40
<span class="linecomment">;;</span>
41
<span class="linecomment">;;</span>
42
43
<span class="linecomment">;;; This file is NOT part of GNU Emacs</span>
44
45
<span class="linecomment">;;; License</span>
46
<span class="linecomment">;;</span>
47
<span class="linecomment">;; This program is free software; you can redistribute it and/or modify</span>
48
<span class="linecomment">;; it under the terms of the GNU General Public License as published by</span>
49
<span class="linecomment">;; the Free Software Foundation; either version 3, or (at your option)</span>
50
<span class="linecomment">;; any later version.</span>
51
52
<span class="linecomment">;; This program is distributed in the hope that it will be useful,</span>
53
<span class="linecomment">;; but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
54
<span class="linecomment">;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
55
<span class="linecomment">;; GNU General Public License for more details.</span>
56
57
<span class="linecomment">;; You should have received a copy of the GNU General Public License</span>
58
<span class="linecomment">;; along with this program; see the file COPYING. If not, write to</span>
59
<span class="linecomment">;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth</span>
60
<span class="linecomment">;; Floor, Boston, MA 02110-1301, USA.</span>
61
62
<span class="linecomment">;;; Commentary:</span>
63
<span class="linecomment">;;</span>
64
<span class="linecomment">;; View CHM file.</span>
65
<span class="linecomment">;;</span>
66
<span class="linecomment">;; This package is view CHM file in Emacs.</span>
67
<span class="linecomment">;; This package use `archmage' decompress</span>
68
<span class="linecomment">;; CHM file and view in browser.</span>
69
<span class="linecomment">;;</span>
70
<span class="linecomment">;; Below are commands you can use:</span>
71
<span class="linecomment">;;</span>
72
<span class="linecomment">;; `chm-view-file' View CHM file.</span>
73
<span class="linecomment">;; `chm-view-dired' View dired marked CHM files.</span>
74
<span class="linecomment">;;</span>
75
76
<span class="linecomment">;;; Installation:</span>
77
<span class="linecomment">;;</span>
78
<span class="linecomment">;; This package is base on `archmage', so make sure</span>
79
<span class="linecomment">;; `archmage' have install in your system, like me</span>
80
<span class="linecomment">;; (I use Debian), install `archmage':</span>
81
<span class="linecomment">;;</span>
82
<span class="linecomment">;; sudo aptitude install archmage -y</span>
83
<span class="linecomment">;;</span>
84
<span class="linecomment">;; And then put chm-view.el to your load-path.</span>
85
<span class="linecomment">;; The load-path is usually ~/elisp/.</span>
86
<span class="linecomment">;; It's set in your ~/.emacs like this:</span>
87
<span class="linecomment">;; (add-to-list 'load-path (expand-file-name "~/elisp"))</span>
88
<span class="linecomment">;;</span>
89
<span class="linecomment">;; And the following to your ~/.emacs startup file.</span>
90
<span class="linecomment">;;</span>
91
<span class="linecomment">;; (require 'chm-view)</span>
92
<span class="linecomment">;;</span>
93
<span class="linecomment">;; That's all, enjoy! :)</span>
94
<span class="linecomment">;;</span>
95
96
<span class="linecomment">;;; Note:</span>
97
<span class="linecomment">;;</span>
98
<span class="linecomment">;; Because “archmage” need time to extract CHM file,</span>
99
<span class="linecomment">;; if browser (such as emacs-w3m) open special port before “archmage” extract completed,</span>
100
<span class="linecomment">;; it will got error “Cannot retrieve URL: http://localhost:531560 (exit status: 0)”,</span>
101
<span class="linecomment">;; then you just refresh current page in browser, problem will be fix.</span>
102
<span class="linecomment">;; If you always get error when open CHM file,</span>
103
<span class="linecomment">;; you need setup a bigger value to option `chm-view-delay' (default is 0.3 second).</span>
104
<span class="linecomment">;;</span>
105
106
<span class="linecomment">;;; Customize:</span>
107
<span class="linecomment">;;</span>
108
<span class="linecomment">;; `chm-view-delay'</span>
109
<span class="linecomment">;; The delay time before view CHM file.</span>
110
<span class="linecomment">;;</span>
111
<span class="linecomment">;; All of the above can customize by:</span>
112
<span class="linecomment">;; M-x customize-group RET chm-view RET</span>
113
<span class="linecomment">;;</span>
114
115
<span class="linecomment">;;; Change log:</span>
116
<span class="linecomment">;;</span>
117
<span class="linecomment">;; 2009/04/16</span>
118
<span class="linecomment">;; * Fix `absolute path' problem with file.</span>
119
<span class="linecomment">;;</span>
120
<span class="linecomment">;; 2009/04/10</span>
121
<span class="linecomment">;; * Fix doc.</span>
122
<span class="linecomment">;;</span>
123
<span class="linecomment">;; 2009/01/29</span>
124
<span class="linecomment">;; * Add option `chm-view-delay'.</span>
125
<span class="linecomment">;;</span>
126
<span class="linecomment">;; 2009/01/28</span>
127
<span class="linecomment">;; * First released.</span>
128
<span class="linecomment">;;</span>
129
130
<span class="linecomment">;;; Acknowledgements:</span>
131
<span class="linecomment">;;</span>
132
<span class="linecomment">;;</span>
133
<span class="linecomment">;;</span>
134
135
<span class="linecomment">;;; TODO</span>
136
<span class="linecomment">;;</span>
137
<span class="linecomment">;;</span>
138
<span class="linecomment">;;</span>
139
140
<span class="linecomment">;;; Require</span>
141
142
143
<span class="linecomment">;;; Code:</span>
144
145
<span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span>
146
(defgroup chm-view nil
147
"<span class="quote">Interface for chm-view.</span>"
148
:group 'edit)
149
150
(defcustom chm-view-delay 0.3
151
"<span class="quote">The delay time before view CHM file.
152
This is necessary spend time to start sub-process.</span>"
153
:type 'number
154
:group 'chm-view)
155
156
<span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span>
157
(defvar chm-view-last-filename nil
158
"<span class="quote">The name of last visit CHM file.</span>")
159
160
(defvar chm-view-pid nil
161
"<span class="quote">The PID of chm-view process.</span>")
162
(make-variable-buffer-local 'chm-view-pid)
163
164
<span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span>
165
(defun chm-view-file (&optional file)
166
"<span class="quote">View CHM FILE.</span>"
167
(interactive)
168
<span class="linecomment">;; Get file name.</span>
169
(or file (setq file (read-file-name (format "<span class="quote">CHM file: (%s) </span>" (or chm-view-last-filename "<span class="quote"></span>"))
170
nil chm-view-last-filename)))
171
<span class="linecomment">;; Record last visit file name.</span>
172
(setq chm-view-last-filename file)
173
<span class="linecomment">;; View.</span>
174
(chm-view-internal file))
175
176
(defun chm-view-dired ()
177
"<span class="quote">View dired marked files.</span>"
178
(interactive)
179
(dolist (file (dired-get-marked-files))
180
(chm-view-internal file)))
181
182
<span class="linecomment">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</span>
183
(defun chm-view-internal (file)
184
"<span class="quote">Internal function for view CHM FILE.</span>"
185
(let ((random-number (chm-view-get-unique-number))
186
proc)
187
(with-current-buffer (get-buffer-create
188
<span class="linecomment">;; Need leave one whitespace before buffer name.</span>
189
(format "<span class="quote"> *chm-view&lt;%s&gt;*</span>" random-number))
190
(setq proc (start-process (buffer-name) (current-buffer)
191
"<span class="quote">archmage</span>" "<span class="quote">-p</span>" random-number (expand-file-name file)))
192
<span class="linecomment">;; Just wait a moment.</span>
193
(sit-for chm-view-delay)
194
<span class="linecomment">;; Browse.</span>
195
(browse-url (format "<span class="quote">http://localhost:%s</span>" random-number))
196
<span class="linecomment">;; Record PID of `chm-view' process.</span>
197
(setq chm-view-pid (process-id proc))
198
<span class="linecomment">;; Add interrupt process of buffer to kill-buffer-hook.</span>
199
(add-hook 'kill-buffer-hook
200
'(lambda ()
201
(when chm-view-pid
202
<span class="linecomment">;; Kill `chm-view' process,</span>
203
<span class="linecomment">;; and don't avoid output message.</span>
204
(flet ((message (&rest args)))
205
(shell-command (format "<span class="quote">kill -9 %s</span>" chm-view-pid)))
206
<span class="linecomment">;; Reset `chm-view-pid'.</span>
207
(setq chm-view-pid nil)))))))
208
209
(defun chm-view-get-unique-number ()
210
"<span class="quote">Get a unique number.</span>"
211
(let (time-now buffer)
212
(setq time-now (current-time))
213
(format "<span class="quote">%s</span>" (nth 2 time-now))))
214
215
(provide 'chm-view)
216
217
<span class="linecomment">;;; chm-view.el ends here</span>
218
219
220
<span class="linecomment">;;; LocalWords: archmage pid args</span></span></pre></div><div class="wrapper close"></div></div><div class="footer"><hr /><span class="gotobar bar"><a class="local" href="http://www.emacswiki.org/emacs/SiteMap">SiteMap</a> <a class="local" href="http://www.emacswiki.org/emacs/Search">Search</a> <a class="local" href="http://www.emacswiki.org/emacs/ElispArea">ElispArea</a> <a class="local" href="http://www.emacswiki.org/emacs/HowTo">HowTo</a> <a class="local" href="http://www.emacswiki.org/emacs/RecentChanges">RecentChanges</a> <a class="local" href="http://www.emacswiki.org/emacs/News">News</a> <a class="local" href="http://www.emacswiki.org/emacs/Problems">Problems</a> <a class="local" href="http://www.emacswiki.org/emacs/Suggestions">Suggestions</a> </span><span class="translation bar"><br /> <a class="translation new" rel="nofollow" href="http://www.emacswiki.org/emacs?action=translate;id=chm-view.el;missing=de_en_es_fr_it_ja_ko_pt_ru_se_zh">Add Translation</a></span><span class="edit bar"><br /> <a class="edit" accesskey="e" title="Click to edit this page" rel="nofollow" href="http://www.emacswiki.org/emacs?action=edit;id=chm-view.el">Edit this page</a> <a class="history" rel="nofollow" href="http://www.emacswiki.org/emacs?action=history;id=chm-view.el">View other revisions</a> <a class="admin" rel="nofollow" href="http://www.emacswiki.org/emacs?action=admin;id=chm-view.el">Administration</a></span><span class="time"><br /> Last edited 2009-04-16 02:50 UTC by <a class="author" title="from 121.13.172.246" href="http://www.emacswiki.org/emacs/AndyStewart">AndyStewart</a> <a class="diff" rel="nofollow" href="http://www.emacswiki.org/emacs?action=browse;diff=2;id=chm-view.el">(diff)</a></span><div style="float:right; margin-left:1ex;">
221
<!-- Creative Commons License -->
222
<a href="http://creativecommons.org/licenses/GPL/2.0/"><img alt="CC-GNU GPL" style="border:none" src="/pics/cc-GPL-a.png" /></a>
223
<!-- /Creative Commons License -->
224
</div>
225
226
<!--
227
<rdf:RDF xmlns="http://web.resource.org/cc/"
228
xmlns:dc="http://purl.org/dc/elements/1.1/"
229
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
230
<Work rdf:about="">
231
<license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
232
<dc:type rdf:resource="http://purl.org/dc/dcmitype/Software" />
233
</Work>
234
235
<License rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
236
<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
237
<permits rdf:resource="http://web.resource.org/cc/Distribution" />
238
<requires rdf:resource="http://web.resource.org/cc/Notice" />
239
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
240
<requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
241
<requires rdf:resource="http://web.resource.org/cc/SourceCode" />
242
</License>
243
</rdf:RDF>
244
-->
245
246
<p class="legal">
247
This work is licensed to you under version 2 of the
248
<a href="http://www.gnu.org/">GNU</a> <a href="/GPL">General Public License</a>.
249
Alternatively, you may choose to receive this work under any other
250
license that grants the right to use, copy, modify, and/or distribute
251
the work, as long as that license imposes the restriction that
252
derivative works have to grant the same rights and impose the same
253
restriction. For example, you may choose to receive this work under
254
the
255
<a href="http://www.gnu.org/">GNU</a>
256
<a href="/FDL">Free Documentation License</a>, the
257
<a href="http://creativecommons.org/">CreativeCommons</a>
258
<a href="http://creativecommons.org/licenses/sa/1.0/">ShareAlike</a>
259
License, the XEmacs manual license, or
260
<a href="/OLD">similar licenses</a>.
261
</p>
262
</div>
263
</body>
264
</html>
265
266