PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/site/nxhtml/util/udev-rinari.el

https://github.com/AriT93/emacs
Emacs Lisp | 204 lines | 128 code | 18 blank | 58 comment | 6 complexity | a3e68dafbab23bd53e7f84df0dd3f27d MD5 | raw file
  1. ;;; udev-rinari.el --- Get rinary sources and set it up
  2. ;;
  3. ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
  4. ;; Created: 2008-08-24T22:32:21+0200 Sun
  5. (defconst udev-rinari:version "0.2");; 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 2, 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. (eval-when-compile (require 'udev))
  47. (defgroup udev-rinari nil
  48. "Customization group for udev-rinari."
  49. :group 'nxhtml)
  50. (defcustom udev-rinari-dir "~/rinari-svn/"
  51. "Directory where to put SVN Rinari sources."
  52. :type 'directory
  53. :group 'udev-rinari)
  54. (defcustom udev-rinari-load-rinari nil
  55. "To load or not to load Rinari..."
  56. :type '(choice (const :tag "Don't load Rinari" nil)
  57. (const :tag "Load Rinari" t))
  58. :set (lambda (sym val)
  59. (set-default sym val)
  60. (when val
  61. (let* ((base-dir (expand-file-name "svn/trunk/" udev-rinari-dir))
  62. (rhtml-dir (expand-file-name "rhtml/" base-dir))
  63. (test-dir (expand-file-name "test/lisp/" base-dir)))
  64. (unless (file-directory-p base-dir) (message "Can't find %s" base-dir))
  65. (unless (file-directory-p rhtml-dir) (message "Can't find %s" rhtml-dir))
  66. (unless (file-directory-p test-dir) (message "Can't find %s" test-dir))
  67. (add-to-list 'load-path base-dir)
  68. (add-to-list 'load-path rhtml-dir)
  69. (add-to-list 'load-path test-dir))
  70. (require 'rinari)
  71. (require 'ruby-mode)))
  72. :group 'udev-rinari)
  73. (defvar udev-rinari-steps
  74. '(udev-rinari-fetch
  75. udev-rinari-fetch-diff
  76. udev-rinari-check-diff
  77. ;;udev-rinari-install
  78. ))
  79. (defvar udev-rinari-update-buffer nil)
  80. (defun udev-rinari-buffer-name (mode)
  81. "Return a name for current compilation buffer ignoring MODE."
  82. (udev-buffer-name "*Updating Rinari %s*" udev-rinari-update-buffer mode))
  83. (defun udev-rinari-check-conflicts ()
  84. "Check if Rinari and ruby-mode already loaded and from where.
  85. Give an error if they are loaded from somewhere else than
  86. `udev-rinari-dir' tree."
  87. (when (featurep 'rinari)
  88. (let ((old-dir (file-name-directory (car (load-history-filename-element (load-history-regexp "rinari")))))
  89. (new-dir (expand-file-name "svn/trunk/" udev-rinari-dir)))
  90. (unless (string= (file-truename old-dir)
  91. (file-truename new-dir))
  92. (error "Rinari is already loaded from: %s" old-dir))))
  93. (when (featurep 'ruby-mode)
  94. (let ((old-dir (file-name-directory (car (load-history-filename-element (load-history-regexp "ruby-mode")))))
  95. (new-dir (expand-file-name "svn/trunk/test/lisp/" udev-rinari-dir)))
  96. (unless (string= (file-truename old-dir)
  97. (file-truename new-dir))
  98. (error "Ruby-mode is already loaded from: %s" old-dir))))
  99. )
  100. (defun udev-rinari-setup-when-finished (log-buffer)
  101. (let ((inhibit-read-only t))
  102. (with-current-buffer log-buffer
  103. (widen)
  104. (goto-char (point-max))
  105. (insert "\n\nYou must restart Emacs to load Rinari properly.\n")
  106. (let ((load-rinari-saved-value (get 'udev-rinari-load-rinari 'saved-value))
  107. (here (point))
  108. )
  109. (if load-rinari-saved-value
  110. (insert "You have setup to load Rinari the next time you start Emacs.\n\n")
  111. (insert (propertize "Warning:" 'face 'compilation-warning)
  112. " You have not setup to load Rinari the next time you start Emacs.\n\n"))
  113. (insert-button " Setup "
  114. 'face 'custom-button
  115. 'action (lambda (btn)
  116. (interactive)
  117. (customize-group-other-window 'udev-rinari)))
  118. (insert " Setup to load Rinari from fetched sources when starting Emacs.")))))
  119. ;;;###autoload
  120. (defun udev-rinari-update ()
  121. "Fetch and install Rinari from the devel sources.
  122. To determine where to store the sources and how to start rinari
  123. see `udev-rinari-dir' and `udev-rinari-load-rinari'."
  124. (interactive)
  125. (udev-rinari-check-conflicts)
  126. (setq udev-rinari-update-buffer (get-buffer-create "*Update Rinari*"))
  127. (udev-call-first-step udev-rinari-update-buffer udev-rinari-steps
  128. "Starting updating Rinari from development sources"
  129. 'udev-rinari-setup-when-finished))
  130. (defvar udev-rinari-fetch-buffer nil)
  131. (defun udev-rinari-fetch (log-buffer)
  132. "Fetch Rinari from development sources."
  133. (let* ((default-directory (file-name-as-directory udev-rinari-dir)) ;; fix-me: for emacs bug
  134. )
  135. (unless (file-directory-p default-directory)
  136. (make-directory default-directory))
  137. (with-current-buffer
  138. (compilation-start
  139. "svn checkout http://rinari.rubyforge.org/svn/"
  140. 'compilation-mode
  141. 'udev-rinari-buffer-name)
  142. (setq udev-rinari-fetch-buffer (current-buffer)))))
  143. (defvar udev-rinari-diff-file nil)
  144. (defvar udev-rinari-fetch-diff-buffer nil)
  145. (defun udev-rinari-fetch-diff (log-buffer)
  146. "Fetch diff between local Rinari sources and dev repository."
  147. (let ((must-fetch-diff t))
  148. (setq udev-rinari-fetch-diff-buffer
  149. (when must-fetch-diff
  150. (let* ((default-directory (file-name-as-directory
  151. (expand-file-name "svn"
  152. udev-rinari-dir))))
  153. (setq udev-rinari-diff-file (expand-file-name "../patches.diff"))
  154. (with-current-buffer
  155. (compilation-start
  156. (concat "svn diff > " (shell-quote-argument udev-rinari-diff-file))
  157. 'compilation-mode
  158. 'udev-rinari-buffer-name)
  159. (setq udev-continue-on-error-function 'udev-cvs-diff-continue)
  160. (current-buffer)))))))
  161. (defun udev-rinari-check-diff (log-buffer)
  162. "Check output from svn diff command for merge conflicts."
  163. ;; Fix-me: How can this be checked?
  164. (when udev-rinari-fetch-diff-buffer
  165. (let ((buf (find-buffer-visiting udev-rinari-diff-file)))
  166. (if buf
  167. (with-current-buffer buf (revert-buffer nil t))
  168. (setq buf (find-file-noselect udev-rinari-diff-file)))
  169. (with-current-buffer buf
  170. (widen)
  171. (goto-char (point-min))
  172. (if (search-forward "<<<<<<<" nil t)
  173. ;; Merge conflict
  174. (udev-call-next-step udev-rinari-update-buffer 1 nil)
  175. buf)))))
  176. ;; (defun udev-rinari-install ()
  177. ;; "Install Rinari and ruby-mode for use."
  178. ;; (if udev-rinari-load-rinari
  179. ;; (message "Rinari should be loaded now")
  180. ;; (when (y-or-n-p
  181. ;; "You need to set udev-rinari-load-rinari. Do that now? ")
  182. ;; (customize-group-other-window 'udev-rinari)))
  183. ;; nil)
  184. (provide 'udev-rinari)
  185. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  186. ;;; udev-rinari.el ends here