]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/nxhtml-web-vcs.el
submodulized .emacs.d setup
[.emacs.d.git] / emacs / nxhtml / nxhtml-web-vcs.el
1 ;;; nxhtml-web-vcs.el --- nXhtml things for web-vcs.el
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2010-01-13 Wed
5 ;; Version:
6 ;; Last-Updated:
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Features that might be required by this library:
12 ;;
13 ;;   None
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;;
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;
23 ;;; Change log:
24 ;;
25 ;;
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;
28 ;; This program is free software; you can redistribute it and/or
29 ;; modify it under the terms of the GNU General Public License as
30 ;; published by the Free Software Foundation; either version 3, or
31 ;; (at your option) any later version.
32 ;;
33 ;; This program is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36 ;; General Public License for more details.
37 ;;
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with this program; see the file COPYING.  If not, write to
40 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
41 ;; Floor, Boston, MA 02110-1301, USA.
42 ;;
43 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
44 ;;
45 ;;; Code:
46
47 (eval-when-compile (require 'cl))
48 (eval-when-compile (require 'nxhtml-base nil t))
49 ;;(eval-when-compile (require 'nxhtmlmaint nil t))
50 (eval-when-compile (require 'web-vcs nil t))
51
52 (defvar nxhtml-web-vcs-file (or load-file-name
53                                 (when (boundp 'bytecomp-filename) bytecomp-filename)
54                                 buffer-file-name)
55   "This file.")
56
57 (defun nxhtml-require-base ()
58   (require 'nxhtml-base nil t)
59   (unless (featurep 'nxhtml-base)
60     ;; At startup, need to load it by hand.
61     (let ((load-path load-path))
62       (add-to-list 'load-path (file-name-directory nxhtml-web-vcs-file))
63       (require 'nxhtml-base))))
64
65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 ;;; Repository URL
67
68
69 ;;(nxhtml-default-download-directory)
70 (defun nxhtml-default-download-directory ()
71   (let* ((ur (expand-file-name "" "~"))
72          (ur-len (length ur))
73          (full (if (and (boundp 'nxhtml-install-dir)
74                         nxhtml-install-dir)
75                    nxhtml-install-dir
76                  (file-name-as-directory
77                   (expand-file-name ""
78                                     (web-vcs-default-download-directory)))))
79          (full-len (length full)))
80     (if (and (> full-len ur-len)
81              (string= ur (substring full 0 ur-len)))
82         (concat "~" (substring full ur-len))
83       full)))
84
85
86 (defun nxhtml-web-vcs-read-dl-dir (prompt)
87   "Return current nXhtml install dir or read dir."
88   (or (and (boundp 'nxhtml-install-dir)
89            nxhtml-install-dir)
90       (let* ((pr (concat
91                   "A directory named 'nxhtml' will be created below the root you give."
92                   "\n"
93                   prompt))
94              (root (read-directory-name pr (nxhtml-default-download-directory))))
95         (when root
96           (expand-file-name "nxhtml" root)))))
97
98 ;;(call-interactively 'nxhtml-setup-install)
99 ;; (read-key "Prompt: ")
100 ;; (y-or-n-p "Prompt")
101 ;;;###autoload
102 (defun nxhtml-setup-install (way)
103   "Setup and start nXhtml installation.
104
105 This is for installation and updating directly from the nXhtml
106 development sources.
107
108 There are two different ways to install:
109
110   (1) Download all at once: `nxhtml-setup-download-all'
111   (2) Automatically download part by part: `nxhtml-setup-auto-download'
112
113 You can convert between those ways by calling this function again.
114 You can also do this by setting the option `nxhtml-autoload-web' yourself.
115
116 When you have nXhtml installed you can update it:
117
118   (3) Update new files in nXhtml: `nxhtml-update-existing-files'
119
120 To learn more about nXhtml visit its home page at URL
121 `http://www.emacswiki.com/NxhtmlMode/'.
122
123 If you want to test auto download \(but not use it further) there
124 is a special function for that, you answer T here:
125
126    (T) Test automatic download part by part: `nxhtml-setup-test-auto-download'
127
128 ======
129 *Note*
130 If you want to download a zip file with latest released version instead then
131 please see URL `http://ourcomments.org/Emacs/nXhtml/doc/nxhtml.html'."
132   (interactive (let ((curr-cfg (current-window-configuration)))
133                  (describe-function 'nxhtml-setup-install)
134                  (select-window (get-buffer-window (help-buffer)))
135                  (delete-other-windows)
136                  (list
137                   (let* ((key nil)
138                          (has-nxhtml (and (boundp 'nxhtml-install-dir) nxhtml-install-dir))
139                          (current-way (if has-nxhtml
140                                           (if (and (boundp 'nxhtml-autoload-web)
141                                                    nxhtml-autoload-web)
142                                               "Your current setup is to download part by part from the web."
143                                             "Your current setup it to download all of nXhtml at once.")
144                                         "(You have not currently installed nXhtml.)"))
145                          (prompt (concat "Setup nXhtml install."
146                                          "\n" current-way
147                                          "\n"
148                                          "\n(1) Download whole at once, or (2) part by part as needed"
149                                          (if has-nxhtml "\n(3) Update your existing nXhtml" "")
150                                          "\n(T) For temporary testing downloading part by part"
151                                          "\n"
152                                          "\n(? for help, q to quit): "))
153                          (allowed-keys (if has-nxhtml
154                                            '(?1 ?2 ?3 ?T ?q 7)
155                                          '(?1 ?2 ?T ?q 7)))
156                          (please nil))
157                     (while (not (member key allowed-keys))
158                       (if (not (member key '(??)))
159                           (when key
160                             (unless please
161                               (setq prompt (concat "Please answer with one of the alternatives.\n\n"
162                                                    prompt))
163                               (setq please t)))
164                         (describe-function 'nxhtml-setup-install)
165                         (select-window (get-buffer-window (help-buffer)))
166                         (delete-other-windows))
167                       (setq key (web-vcs-read-key prompt))
168                       ;;(message "key = %S" key) (sit-for 1)
169                       )
170                     (case key
171                       (7 (set-window-configuration curr-cfg)
172                          nil)
173                       (?1 'whole)
174                       (?2 'part-by-part)
175                       (?3 'update-existing)
176                       (?T 'test-part-by-part)
177                       )))))
178   (message "")
179   (case way
180     (whole             (call-interactively 'nxhtml-setup-download-all))
181     (part-by-part      (call-interactively 'nxhtml-setup-auto-download))
182     (update-existing   (call-interactively 'nxhtml-update-existing-files))
183     (test-part-by-part (call-interactively 'nxhtml-setup-test-auto-download))
184     ((eq nil way) nil)
185     (t (error "Unknown way = %S" way))))
186
187 (defvar nxhtml-basic-files '(
188                              "nxhtml-base.el"
189                              "nxhtml-loaddefs.el"
190                              "web-autoload.el"
191                              "etc/schema/schema-path-patch.el"
192                              "nxhtml/nxhtml-autoload.el"
193                              "autostart.el"
194                              ))
195
196 ;;;###autoload
197 (defun nxhtml-setup-auto-download (dl-dir)
198   "Set up to autoload nXhtml files from the web.
199
200 This function will download some initial files and then setup to
201 download the rest when you need them.
202
203 Files will be downloaded under the directory root you specify in
204 DL-DIR.
205
206 Note that files will not be upgraded automatically.  The auto
207 downloading is just for files you are missing. (This may change a
208 bit in the future.) If you want to upgrade those files that you
209 have downloaded you can just call `nxhtml-update-existing-files'.
210
211 You can easily switch between this mode of downloading or
212 downloading the whole of nXhtml by once.  To switch just call the
213 command `nxhtml-setup-install'.
214
215 See also the command `nxhtml-setup-download-all'.
216
217 Note: If your nXhtml is to old you can't use this function
218       directly.  You have to upgrade first, se the function
219       above. Version 2.07 or above is good for this."
220   (interactive (progn
221                  (describe-function 'nxhtml-setup-auto-download)
222                  (select-window (get-buffer-window (help-buffer)))
223                  (delete-other-windows)
224                  (nxhtml-check-convert-to-part-by-part)
225                  (list
226                   (progn
227                     (when (and (boundp 'nxhtml-autoload-web)
228                                (not nxhtml-autoload-web))
229                       (unless (yes-or-no-p "Convert to updating nXhtml part by part? ")
230                         (throw 'command-level nil)))
231                     (nxhtml-web-vcs-read-dl-dir "Download nXhtml part by part to directory: ")))))
232   (catch 'command-level
233     (if (not dl-dir)
234         (unless (with-no-warnings (called-interactively-p))
235           (error "dl-dir should be a directory"))
236       (nxhtml-check-convert-to-part-by-part)
237       (when (and (boundp 'nxhtml-install-dir)
238                  nxhtml-install-dir)
239         (unless (string= (file-truename dl-dir)
240                          (file-truename nxhtml-install-dir))
241           (error "Download dir must be same as nxhtml-install-dir=%S" nxhtml-install-dir)))
242       (let* (;; Need some files:
243              (web-vcs-el-src (concat (file-name-sans-extension web-vcs-el-this) ".el"))
244              (web-vcs-el (expand-file-name (file-name-nondirectory web-vcs-el-src)
245                                            dl-dir))
246              (vcs 'lp)
247              (base-url (nxhtml-download-root-url nil))
248              (byte-comp (if (boundp 'web-autoload-autocompile)
249                             web-autoload-autocompile
250                           t))
251              (has-nxhtml (and (boundp 'nxhtml-install-dir)
252                               nxhtml-install-dir))
253              (web-vcs-folder-cache nil))
254         (setq nxhtml-install-dir dl-dir)
255         (let ((root (file-name-directory dl-dir)))
256           (unless (file-exists-p root)
257             (unless (yes-or-no-p (format "Directory %S does not exist, create it? " root))
258               (error "Aborted by user"))))
259         (make-directory dl-dir t)
260         (setq message-log-max t)
261         (view-echo-area-messages)
262         (message "")
263         (message "")
264         (web-vcs-message-with-face 'web-vcs-green "==== Starting nXhtml part by part state ====")
265         (message "has-nxhtml=%s" has-nxhtml)
266         ;; Fix-me: First copy this file and web-vcs.el to its destination:
267         (unless (string= (file-truename dl-dir)
268                          (file-truename (file-name-directory nxhtml-web-vcs-file)))
269           (dolist (f (list web-vcs-el-src nxhtml-web-vcs-file))
270             (copy-file f (expand-file-name (file-name-nondirectory f) dl-dir)
271                        'ok-overwrite)))
272         (when byte-comp (web-vcs-byte-compile-newer-file web-vcs-el t))
273         ;; Get basic file list:
274         (catch 'web-autoload-comp-restart
275           ;;(let ((file-mask (regexp-opt nxhtml-basic-files)))
276           ;;  (web-vcs-get-missing-matching-files vcs base-url dl-dir file-mask))
277           (dolist (f nxhtml-basic-files)
278             (web-vcs-get-missing-matching-files vcs base-url dl-dir f))
279           ;; Autostart.el has not run yet, add download dir to load-path.
280           (let ((load-path (cons (file-name-directory web-vcs-el) load-path)))
281             (when byte-comp
282               (dolist (file nxhtml-basic-files)
283                 (let ((el-file (expand-file-name file dl-dir)))
284                   (web-vcs-byte-compile-newer-file el-file nil)))))
285           (let ((autostart-file (expand-file-name "autostart" dl-dir)))
286             ;;(ad-deactivate 'require)
287             (web-vcs-set&save-option 'nxhtml-autoload-web t)
288             (web-vcs-log nil nil "* nXhtml: Download Part by Part as Needed\n")
289             (load autostart-file)
290             (unless (ad-is-active 'require) (ad-activate 'require))
291             (web-vcs-log-save)
292             (web-vcs-message-with-face 'web-vcs-green "==== Basic files for nXhtml part by part are now installed ====")
293             (web-vcs-display-messages t)
294             (unless has-nxhtml (nxhtml-add-loading-to-custom-file autostart-file t))))))))
295
296 ;;(call-interactively 'nxhtml-download)
297 ;;;###autoload
298 (defun nxhtml-setup-download-all (dl-dir)
299   "Download or update all of nXhtml.
300
301 You can download all if nXhtml with this command.
302
303 To update existing files use `nxhtml-update-existing-files'.
304
305 If you want to download only those files you are actually using
306 then call `nxhtml-setup-auto-download' instead.
307
308 See the command `nxhtml-setup-install' for a convenient way to
309 call these commands.
310
311 For more information about auto download of nXhtml files see
312 `nxhtml-setup-auto-download'."
313   (interactive (progn
314                  (describe-function 'nxhtml-setup-auto-download)
315                  (select-window (get-buffer-window (help-buffer)))
316                  (delete-other-windows)
317                  ;;(nxhtml-check-convert-to-part-by-part)
318                  (list
319                   (nxhtml-web-vcs-read-dl-dir "Download whole nXhtml to directory: "))))
320
321   (let ((root (file-name-directory dl-dir)))
322     (unless (file-exists-p root)
323       (unless (yes-or-no-p (format "Directory %S does not exist, create it? " root))
324         (error "Aborted by user"))))
325   (make-directory dl-dir t)
326   (let ((msg (concat "Downloading nXhtml through Launchpad web interface will take rather long\n"
327                      "time (5-15 minutes) so you may want to do it in a separate Emacs session.\n\n"
328                      "Do you want to download using this Emacs session? "
329                      )))
330     (if (not (y-or-n-p msg))
331         (message "Aborted")
332       (setq message-log-max t)
333       (let ((do-byte (y-or-n-p "Do you want to byte compile the files after downloading? ")))
334         (nxhtml-download-1 dl-dir nil do-byte)))))
335
336
337 (defun nxhtml-download-1 (dl-dir revision do-byte)
338   "Download nXhtml to directory DL-DIR.
339 If REVISION is nil download latest revision, otherwise the
340 specified one.
341
342 If DO-BYTE is non-nil byte compile nXhtml after download."
343   (let* ((has-nxhtml (and (boundp 'nxhtml-install-dir)
344                           nxhtml-install-dir))
345          (base-url nxhtml-web-vcs-base-url)
346          (files-url (concat base-url "files/"))
347          ;;(revs-url  (concat base-url "changes/"))
348          (rev-part (if revision (number-to-string revision) "head%3A/"))
349          (full-root-url (concat files-url rev-part))
350          (web-vcs-folder-cache nil)
351          (web-autoload-paranoid nil))
352     ;;(nxhtml-require-base)
353     (when (web-vcs-get-files-from-root 'lp full-root-url dl-dir)
354       (web-vcs-display-messages t)
355       (web-vcs-log nil nil "* nXhtml: Download All\n")
356       (web-vcs-set&save-option 'nxhtml-autoload-web nil)
357       (message "")
358       (web-vcs-message-with-face 'web-vcs-green "==== Starting downloading whole nXhtml ====")
359       (let ((autostart-file (expand-file-name "autostart" dl-dir)))
360         (load autostart-file)
361         (web-vcs-log-save)
362         (web-vcs-message-with-face 'web-vcs-green "==== All files for nXhtml are now installed ====")
363         (nxhtmlmaint-byte-recompile)
364         (unless has-nxhtml (nxhtml-add-loading-to-custom-file autostart-file nil))))))
365
366 (defun nxhtml-check-convert-to-part-by-part ()
367   (when (and (boundp 'nxhtml-install-dir)
368              nxhtml-install-dir)
369     (unless (and (boundp 'nxhtml-autoload-web)
370                  nxhtml-autoload-web)
371       (if (not (boundp 'nxhtml-menu:version))
372           (error "nxhtml-install-dir set but no version found")
373         (unless (string-match "[\.0-9]+" nxhtml-menu:version)
374           (error "Can't find current version nxhtml-menu:version=%S" nxhtml-menu:version))
375         (let* ((ver-str (match-string 0 nxhtml-menu:version))
376                (ver-num (string-to-number ver-str)))
377           (when (< ver-num 2.07)
378             (web-vcs-message-with-face 'web-vcs-red "Too old nXhtml for download part by part.")
379             (throw 'command-level nil)))))))
380
381
382 ;;(directory-files default-directory nil "\\el$")
383 ;;(directory-files default-directory nil "[^#~]$")
384 ;;;###autoload
385 (defun nxhtml-update-existing-files ()
386   "Update existing nXhtml files from the development sources.
387 Only files you already have will be updated.
388
389 Note that this works both if you have setup nXhtml to auto
390 download files as you need them or if you have downloaded all of
391 nXhtml at once.
392
393 For more information about installing and updating nXhtml see the
394 command `nxhtml-setup-install'."
395   ;; Fix-me: download new files too if you are not auto downloading.
396   (interactive)
397   (when (y-or-n-p "Do you want to update your nXhtml files? ")
398     (message "")
399     (web-vcs-display-messages t)
400     (web-vcs-message-with-face 'web-vcs-yellow "*\nStarting updating your nXhtml files.\n*\n")
401     (message nil)
402     (web-vcs-clear-folder-cache)
403     (let ((vcs 'lp)
404           (base-url (nxhtml-download-root-url nil))
405           (dl-dir nxhtml-install-dir)
406           web-vcs-folder-cache)
407       (setq dl-dir (file-name-as-directory dl-dir))
408       (web-vcs-update-existing-files vcs base-url dl-dir dl-dir)
409       (web-vcs-clear-folder-cache))
410     (display-buffer (get-buffer-create "*Compile-Log*"))
411     (nxhtmlmaint-byte-recompile)
412     (web-vcs-log-save)
413     (web-vcs-message-with-face 'web-vcs-yellow "*\nFinished updating your nXhtml files.\n*\n")
414     (message nil)))
415
416
417 ;;(nxhtml-maybe-download-files (expand-file-name "nxhtml/doc/img/" nxhtml-install-dir) nil)
418 ;;;###autoload
419 (defun nxhtml-get-missing-files (sub-dir file-name-list)
420   (let (file-mask
421         (root-url (nxhtml-download-root-url nil))
422         files-regexp
423         (full-dir (expand-file-name sub-dir nxhtml-install-dir))
424         miss-names)
425     (if file-name-list
426         (progn
427           (dolist (f file-name-list)
428             (let ((full-f (expand-file-name f full-dir)))
429               (unless (file-exists-p full-f)
430                 (setq miss-names (cons f miss-names)))))
431           (setq files-regexp (regexp-opt miss-names)))
432       (setq files-regexp ".*"))
433     ;;(unless (file-exists-p full-dir) (make-directory full-dir t))
434     (setq file-mask
435           (concat (file-relative-name (file-name-as-directory full-dir)
436                                       nxhtml-install-dir)
437                   files-regexp))
438     (let ((web-vcs-folder-cache nil))
439       (web-vcs-get-missing-matching-files 'lp root-url nxhtml-install-dir
440                                           file-mask))))
441
442 ;; Fix-me: Does not work, Emacs Bug
443 ;; Maybe use wget? http://gnuwin32.sourceforge.net/packages/wget.htm
444 ;; http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=5103
445 ;; (nxhtml-get-release-revision)
446 (defun nxhtml-get-release-revision ()
447   "Get revision number for last release."
448   (let* ((all-rev-url "http://code.launchpad.net/%7Enxhtml/nxhtml/main")
449          (url-buf (url-retrieve-synchronously all-rev-url))
450          (vcs-rec (or (assq 'lp web-vcs-links-regexp)
451                       (error "Does not know web-vcs 'lp")))
452          (rel-ver-regexp (nth 6 vcs-rec))
453          )
454     (message "%S" url-buf)
455     (with-current-buffer url-buf
456       (when (re-search-forward rel-ver-regexp nil t)
457         (match-string 1)))))
458
459 ;;;###autoload
460 (defun nxhtml-byte-compile-file (file &optional load)
461   (let ((extra-load-path (when nxhtml-install-dir
462                            (mapcar (lambda (p)
463                                      (file-name-as-directory
464                                       (expand-file-name p nxhtml-install-dir)))
465                                    '("tests" "related" "nxhtml" "util" ".")))))
466     ;; (message "nxhtml-byte-compile-file:extra-load-path=%s" extra-load-path)
467     (web-vcs-byte-compile-file file load extra-load-path)))
468
469 ;; fix-me: change web-vcs-byte-compile-file instead
470 ;;;###autoload
471 (defun nxhtml-byte-recompile-file (file &optional load)
472   "Byte recompile FILE file if necessary.
473 For more information see `nxhtml-byte-compile-file'.
474 Loading is done if recompiled and LOAD is t."
475   (interactive (list (buffer-file-name)
476                      t))
477   (let ((elc-file (byte-compile-dest-file file)))
478     (if (file-newer-than-file-p file elc-file)
479         (nxhtml-byte-compile-file file load)
480       (message "Byte compilation of this file is up to date."))))
481
482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
483 ;;; Add to custom file
484
485
486 (defvar nxhtml-handheld-wincfg nil)
487 (defun nxhtml-handheld-restore-wincg ()
488   (when nxhtml-handheld-wincfg
489     (set-window-configuration nxhtml-handheld-wincfg)
490     (setq nxhtml-handheld-wincfg nil)))
491
492 ;;(nxhtml-handheld-add-loading-to-custom-file "TEST-ME")
493 (defun nxhtml-handheld-add-loading-to-custom-file (file-to-load)
494   (setq nxhtml-handheld-wincfg (current-window-configuration))
495   (delete-other-windows)
496   (let ((info-buf (get-buffer-create "Information about how to add nXhtml to (custom-file)"))
497         (load-str (format "(load %S)" file-to-load)))
498     (with-current-buffer info-buf
499       (add-hook 'kill-buffer-hook 'nxhtml-handheld-restore-wincg nil t)
500       (insert "Insert the following line to (custom-file), ie the file in the other window:\n\n")
501       (let ((here (point)))
502         (insert "  "
503                 (propertize load-str 'face 'secondary-selection)
504                 "\n")
505         (copy-region-as-kill here (point))
506         (insert "\nThe line above is in the clipboard so you can just paste it where you want it.\n")
507         (insert "When ready kill this buffer.")
508         (goto-char here))
509       (setq buffer-read-only t)
510       (set-buffer-modified-p nil))
511     (set-window-buffer (selected-window) info-buf)
512     (find-file-other-window (custom-file))))
513
514 ;; (nxhtml-add-loading-to-custom-file "test-file")
515 (defun nxhtml-add-loading-to-custom-file (file-to-load part-by-part)
516   (message "")
517   (require 'cus-edit)
518   (if (not (condition-case nil (custom-file) (error nil)))
519       (progn
520         (message "\n\n")
521         (web-vcs-message-with-face
522          'web-vcs-red
523          (concat "Since you have started this Emacs session without running your init files"
524                  "\nthey are unknown and the installation can not add the statement below."
525                  "\nTo finish the setup of nXhtml you must add"
526                  "\n\n  (load %S)"
527                  "\n\nto your custom-file if you have not done it yet."
528                  "\nYou must also customize the variable `nxhtml-autoload-web' to tell that"
529                  (if part-by-part
530                      "\nyou want to download nXhml files as you need them."
531                    "\nyou do not want to allow automatic downloading of nXhtml files."
532                    )
533                  "\n")
534          file-to-load)
535         (message "")
536         (web-vcs-display-messages t))
537     (let ((prompt (concat "Basic setup of nXhtml is done, but it must be loaded from (custom-file)."
538                           "\nShould I add loading of nXhtml to (custom-file) for you? ")))
539       (if (yes-or-no-p prompt)
540           (nxhtml-add-loading-to-custom-file-auto file-to-load)
541         (if (yes-or-no-p "Should I guide you through how to do it? ")
542             (nxhtml-handheld-add-loading-to-custom-file file-to-load)
543           (web-vcs-message-with-face 'web-vcs-green
544                                      "OK. You need to add (load %S) to your init file" file-to-load))))))
545
546 ;; Fix-me: really do this? Is it safe enough?
547 (defun nxhtml-add-loading-to-custom-file-auto (file-to-load)
548   (unless (file-name-absolute-p file-to-load)
549     (error "nxhtml-add-loading-to-custom-file: Not abs file name: %S" file-to-load))
550   (let ((old-buf (find-buffer-visiting (custom-file)))
551         (full-to-load (expand-file-name file-to-load)))
552     (with-current-buffer (or old-buf (find-file-noselect (custom-file)))
553       (save-restriction
554         (widen)
555         (catch 'done
556           (while (progn
557                    (while (progn (skip-chars-forward " \t\n\^l")
558                                  (looking-at ";"))
559                      (forward-line 1))
560                    (not (eobp)))
561             (let ((start (point))
562                   (form (read (current-buffer))))
563               (when (eq (nth 0 form) 'load)
564                 (let* ((form-file (nth 1 form))
565                        (full-form-file (expand-file-name form-file)))
566                   (when (string= full-form-file full-to-load)
567                     (throw 'done nil))
568                   (when (and (string= (file-name-nondirectory full-form-file)
569                                       (file-name-nondirectory full-to-load))
570                              (not (string= full-form-file full-to-load)))
571                     (if (yes-or-no-p "Replace current nXhtml loading in (custom-file)? ")
572                         (progn
573                           (goto-char start) ;; at form start now
574                           (forward-char (length "(load "))
575                           (skip-chars-forward " \t\n\^l") ;; at start of string
576                           (setq start (point))
577                           (setq form (read (current-buffer)))
578                           (delete-region start (point))
579                           (insert (format "%S" full-to-load))
580                           (basic-save-buffer))
581                       (web-vcs-message-with-face 'web-vcs-red "Can't continue then")
582                       (web-vcs-display-messages t)
583                       (throw 'command-level nil)))))))
584           ;; At end of file
585           (insert (format "\n(load  %S)\n" file-to-load))
586           (basic-save-buffer))
587         (unless old-buf (kill-buffer old-buf))))))
588
589 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
590 ;;;;;; Start Testing function
591 (defun emacs-Q-no-nxhtml (&rest args)
592   (let* ((old-env-load-path (getenv "EMACSLOADPATH"))
593          sub-env-load-path
594          (elp-list (or (when old-env-load-path
595                          ;;(split-string old-env-load-path ";"))
596                          (split-string old-env-load-path path-separator))
597                        load-path))
598          (sub-elp-list nil)
599          ret
600          (this-emacs-exe (locate-file invocation-name
601                                       (list invocation-directory)
602                                       exec-suffixes)))
603     (dolist (p elp-list)
604       (when (file-exists-p p)
605         (unless (string= nxhtml-install-dir p)
606           (let* ((dir (file-name-directory p))
607                  (last (file-name-nondirectory p))
608                  (last-dir (file-name-nondirectory
609                             (directory-file-name dir))))
610             (unless (and (string= "nxhtml" last-dir)
611                          (member last '("util" "test" "nxhtml" "related" "alt")))
612               (setq sub-elp-list (cons p sub-elp-list)))))))
613     ;;(setq sub-env-load-path (mapconcat 'identity (reverse sub-elp-list) ";"))
614     (setq sub-env-load-path (mapconcat 'identity (reverse sub-elp-list) path-separator))
615     (setenv "EMACSLOADPATH" sub-env-load-path)
616     (setq ret (apply 'call-process this-emacs-exe nil 0 nil "-Q" args))
617     (setenv "EMACSLOADPATH" old-env-load-path)
618     ret))
619
620 ;; (call-interactively-p 'nxhtml-setup-test-auto-download)
621 ;; (nxhtml-setup-test-auto-download "c:/test2/")
622 (defun nxhtml-setup-test-auto-download (test-dir)
623   "Test autoload in a new emacs, started with 'emacs -Q'.
624 You can choose where to download the files and just delete them
625 when you have tested enough."
626   (interactive (list (read-directory-name "Directory for test of auto download of nXhtml: ")))
627   (let ((this-dir (file-name-directory web-vcs-el-this))
628         (this-name (file-name-nondirectory web-vcs-el-this))
629         that-file)
630     (when (and (file-exists-p test-dir)
631                (not (y-or-n-p (format "Directory %S exists, really test there? " test-dir))))
632       (error "Aborted"))
633     (unless (file-exists-p test-dir) (make-directory test-dir))
634     (setq that-file (expand-file-name this-name test-dir))
635     (when (file-exists-p that-file) (delete-file that-file))
636     (copy-file web-vcs-el-this that-file)
637     (emacs-Q-no-nxhtml "-l" that-file "-f" "nxhtml-setup-test-auto-download-do-it-here")))
638
639 (defun nxhtml-setup-test-auto-download-do-it-here ()
640   "Helper for `nxhtml-setup-test-auto-down-load'."
641   (let ((this-dir (file-name-directory web-vcs-el-this)))
642     (nxhtml-setup-auto-download this-dir)))
643
644 (defun web-vcs-check-if-modified ()
645   (let (
646         (t1 (format-time-string "%Y-%m-%dT%T%z" (date-to-time "2010-01-01 18:20")))
647         (t2 (format-time-string "%Y-%m-%dT%T%z" (date-to-time "Mon, 28 Dec 2009 08:57:44 GMT")))
648         (url-request-extra-headers
649          (list
650           (cons "If-Modified-Since"
651                 (format-time-string
652                  ;;"%Y-%m-%dT%T%z"
653                  "%a, %e %b %Y %H:%M:%S GMT"
654                  (nth 5 (file-attributes "c:/test/temp.el" )))
655                 )))
656         xb)
657     (setq xb (url-retrieve-synchronously "http://www.emacswiki.org/emacs/download/anything.el"))
658     (switch-to-buffer xb)
659     ))
660 ;; (emacs-Q-no-nxhtml "web-vcs.el" "-l" "c:/test/d27/web-autostart.el")
661 ;; (emacs-Q-no-nxhtml "web-vcs.el" "-l" "c:/test/d27/autostart.el")
662 ;; (emacs-Q-no-nxhtml "web-vcs.el" "-f" "eval-buffer" "-f" "nxhtml-temp-setup-auto-download")
663 ;; (emacs-Q-no-nxhtml "-l" "c:/test/d27/web-vcs" "-l" "c:/test/d27/nxhtml-web-vcs" "-f" "nxhtml-temp-setup-auto-download")
664 ;; (emacs-Q-no-nxhtml "-l" "c:/test/d27/nxhtml-web-vcs" "-f" "nxhtml-temp-setup-auto-download")
665 ;; (emacs-Q-no-nxhtml "--geometry=200x50+100+100" "-l" "c:/test/d27/web-vcs" "-f" "web-vcs-nxhtml")
666 (defun nxhtml-temp-setup-auto-download ()
667   ;;(when (fboundp 'w32-send-sys-command) (w32-send-sys-command #xf030) (sit-for 2))
668   (set-frame-size (selected-frame)
669                   (/ 1024 (frame-char-width))
670                   (/ 512 (frame-char-height))
671                   )
672   (tool-bar-mode -1)
673   (set-frame-position (selected-frame) 100 50)
674   (when (y-or-n-p "Do nXhtml? ")
675     (view-echo-area-messages)
676     (setq truncate-lines t)
677     (split-window-horizontally)
678     (let ((load-path (cons default-directory load-path)))
679       (require 'web-vcs))
680     ;(nxhtml-setup-auto-download "c:/test/d27")
681     (call-interactively 'nxhtml-setup-auto-download)
682     ))
683 ;;;;;; End Testing function
684 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
685
686
687 (provide 'nxhtml-web-vcs)
688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
689 ;;; nxhtml-web-vcs.el ends here