<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<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" />
<link rel="alternate" type="application/rss+xml"
title="Emacs Wiki with page content"
href="http://www.emacswiki.org/emacs/full.rss" />
<link rel="alternate" type="application/rss+xml"
title="Emacs Wiki with page content and diff"
href="http://www.emacswiki.org/emacs/full-diff.rss" />
<link rel="alternate" type="application/rss+xml"
title="Emacs Wiki including minor differences"
href="http://www.emacswiki.org/emacs/minor-edits.rss" />
<link rel="alternate" type="application/rss+xml"
title="Changes for chm-view.el only"
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>
<!-- Google CSE Search Box Begins -->
<form class="tiny" action="http://www.google.com/cse" id="searchbox_004774160799092323420:6-ff2s0o6yi"><p>
<input type="hidden" name="cx" value="004774160799092323420:6-ff2s0o6yi" />
<input type="text" name="q" size="25" />
<input type="submit" name="sa" value="Search" />
</p></form>
<script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_004774160799092323420%3A6-ff2s0o6yi"></script>
<!-- Google CSE Search Box Ends -->
<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&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">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
<span class="linecomment">
(defgroup chm-view nil
"<span class="quote">Interface for chm-view.</span>"
:group 'edit)
(defcustom chm-view-delay 0.3
"<span class="quote">The delay time before view CHM file.
This is necessary spend time to start sub-process.</span>"
:type 'number
:group 'chm-view)
<span class="linecomment">
(defvar chm-view-last-filename nil
"<span class="quote">The name of last visit CHM file.</span>")
(defvar chm-view-pid nil
"<span class="quote">The PID of chm-view process.</span>")
(make-variable-buffer-local 'chm-view-pid)
<span class="linecomment">
(defun chm-view-file (&optional file)
"<span class="quote">View CHM FILE.</span>"
(interactive)
<span class="linecomment">
(or file (setq file (read-file-name (format "<span class="quote">CHM file: (%s) </span>" (or chm-view-last-filename "<span class="quote"></span>"))
nil chm-view-last-filename)))
<span class="linecomment">
(setq chm-view-last-filename file)
<span class="linecomment">
(chm-view-internal file))
(defun chm-view-dired ()
"<span class="quote">View dired marked files.</span>"
(interactive)
(dolist (file (dired-get-marked-files))
(chm-view-internal file)))
<span class="linecomment">
(defun chm-view-internal (file)
"<span class="quote">Internal function for view CHM FILE.</span>"
(let ((random-number (chm-view-get-unique-number))
proc)
(with-current-buffer (get-buffer-create
<span class="linecomment">
(format "<span class="quote"> *chm-view<%s>*</span>" random-number))
(setq proc (start-process (buffer-name) (current-buffer)
"<span class="quote">archmage</span>" "<span class="quote">-p</span>" random-number (expand-file-name file)))
<span class="linecomment">
(sit-for chm-view-delay)
<span class="linecomment">
(browse-url (format "<span class="quote">http://localhost:%s</span>" random-number))
<span class="linecomment">
(setq chm-view-pid (process-id proc))
<span class="linecomment">
(add-hook 'kill-buffer-hook
'(lambda ()
(when chm-view-pid
<span class="linecomment">
<span class="linecomment">
(flet ((message (&rest args)))
(shell-command (format "<span class="quote">kill -9 %s</span>" chm-view-pid)))
<span class="linecomment">
(setq chm-view-pid nil)))))))
(defun chm-view-get-unique-number ()
"<span class="quote">Get a unique number.</span>"
(let (time-now buffer)
(setq time-now (current-time))
(format "<span class="quote">%s</span>" (nth 2 time-now))))
(provide 'chm-view)
<span class="linecomment">
<span class="linecomment">
<!-- Creative Commons License -->
<a href="http://creativecommons.org/licenses/GPL/2.0/"><img alt="CC-GNU GPL" style="border:none" src="/pics/cc-GPL-a.png" /></a>
<!-- /Creative Commons License -->
</div>
<!--
<rdf:RDF xmlns="http://web.resource.org/cc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="">
<license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
<dc:type rdf:resource="http://purl.org/dc/dcmitype/Software" />
</Work>
<License rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
<permits rdf:resource="http://web.resource.org/cc/Reproduction" />
<permits rdf:resource="http://web.resource.org/cc/Distribution" />
<requires rdf:resource="http://web.resource.org/cc/Notice" />
<permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
<requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
<requires rdf:resource="http://web.resource.org/cc/SourceCode" />
</License>
</rdf:RDF>
-->
<p class="legal">
This work is licensed to you under version 2 of the
<a href="http://www.gnu.org/">GNU</a> <a href="/GPL">General Public License</a>.
Alternatively, you may choose to receive this work under any other
license that grants the right to use, copy, modify, and/or distribute
the work, as long as that license imposes the restriction that
derivative works have to grant the same rights and impose the same
restriction. For example, you may choose to receive this work under
the
<a href="http://www.gnu.org/">GNU</a>
<a href="/FDL">Free Documentation License</a>, the
<a href="http://creativecommons.org/">CreativeCommons</a>
<a href="http://creativecommons.org/licenses/sa/1.0/">ShareAlike</a>
License, the XEmacs manual license, or
<a href="/OLD">similar licenses</a>.
</p>
</div>
</body>
</html>