Support Requests: Browse | Submit New | Admin

[#17840] Enhance server buffer

Date:
2008-02-06 21:13
Priority:
3
Submitted By:
Perry Smith (pedz)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Enhance server buffer

Detailed description
If Mongrel is used, these changes add two nice features.  I am not sure what happens to all this if WeBrick is used.

One is the buffer is properly colored.  

The other is next-error will put you at the next error in the last error stack.  This is a little awkward to use.  It
is best to be in the *RWebServer* buffer but you do not have to be.  Then do <prefix-arg>next-error C-u C-x `
(thats a backquote).  The prefix arg will find the last Processing line, then search forward for the stack.  The next
C-x ` will put you at the next entry on the stack.  Be careful if you have a *grep* buffer because next-error will prefer
to look at those "errors" rather than the ones in *RWebServer*.

*** rails-ws.el-orig	Mon Feb  4 10:30:01 2008
--- rails-ws.el	Wed Feb  6 14:55:31 2008
***************
*** 45,50 ****
--- 45,62 ----
    :type 'string
    :tag "Rails Server Type")
  
+ (defcustom rails-ws:grep-args "-Ea"	;use egrep and its not a binary file
+   "Flag args for grep to find parameters"
+   :group 'rails
+   :type 'string
+   :tag "Rails Grep Args")
+ 
+ (defcustom rails-ws:grep-pattern "^  Parameters:"
+   "Pattern to grep for to find parameters"
+   :group 'rails
+   :type 'string
+   :tag "Rails Grep Pattern")
+ 
  (defvar rails-ws:available-servers-list (list "mongrel" "lighttpd" "webrick"))
  (defvar rails-ws:buffer-name "*RWebServer*")
  (defvar rails-ws:process-environment nil)
***************
*** 188,191 ****
                       (read-from-minibuffer "Parameters: "))))
       (message "You can auto-open browser only in view or controller"))))
  
! (provide 'rails-ws)
\ No newline at end of file
--- 240,313 ----
                       (read-from-minibuffer "Parameters: "))))
       (message "You can auto-open browser only in view or controller"))))
  
! (defun rails-ws:next-error ( arg reset )
!   "Hook for compile-next-error.  If reset is true, then from the end of the buffer, find the line that caused
the error.
!   i.e. search back to the stop of the last stack and then put
!   point at the line number for the indicated file."
!   (if reset
!       (progn
! 	(message (buffer-name (current-buffer)))
! 	(goto-char (point-max))
! 	(re-search-backward "^Processing")
! 	(re-search-forward "^    ")
! 	(beginning-of-line)))
! 
!   ;; The first group is not used.  We may have just search backwards
!   ;; and are sitting at Error (/file/name:18 ...  In that case, the
!   ;; first part of the first group finds "(/" -- this will skip errors
!   ;; with messages (Syntax Error seems to be a special case -- this is
!   ;; to catch that special case).  Otherwise, the first part scans the
!   ;; white space as well as the leading /.  We have to scan the / here
!   ;; because we scanned it in the other part.  We will add it back in
!   ;; later.  The next two groups are pretty obvious.  One is to find
!   ;; the file name up to a colon.  The second is to find the line
!   ;; number.  The last group is not used as well.  It finds either a
!   ;; colon or an end of line.
! 
!   (re-search-forward "^\\ \\ \\ \\ /?\\([^:\n]+\\):\\([0-9]+\\)\\(:\\|$\\)" nil nil arg)
!   (message (format "%s" (point-marker)))
!   (let ((file-name (concat "/" (match-string 1)))
! 	(line-number (string-to-number (match-string 2))))
!     (message (format "file is %s line is %d" file-name line-number))
!     (if (file-exists-p (concat "." file-name))
! 	(setq file-name (concat "." file-name)))
!     (with-current-buffer (find-file file-name)
!       (goto-line line-number))))
! 
! (defun rails-ws:last-parameters ()
!   "Returns a hash of the last parameters found in the log file for the
!   currently running server"
!   (let ((buf (get-buffer-create "some-random-name"))
! 	(root (rails-project:root))
! 	(env rails-ws:process-environment)
! 	(hash (make-hash-table :test 'equal :size 5)))
!     (with-current-buffer buf
!       (erase-buffer)
!       (call-process-region (point)	;start
! 			   (point)	;end
! 			   "grep"	;program
! 			   nil		;don't delete buffer
! 			   t		;output to current buffer
! 			   nil		;no display
! 			   rails-ws:grep-args
! 			   rails-ws:grep-pattern
! 			   (concat root "log/" env ".log")) ;path
! 
!       (goto-char (point-max))
!       (forward-line -1)
!       (while (re-search-forward "\"\\([^\"]*\\)\"=>\"\\([^\"]*\\)\"" nil
t)
! 	(puthash (match-string 1) (match-string 2) hash))
!       hash)))
! 
! 
! (defun rails-ws:last-action ()
!   "Display action last executed according to the log file"
!   (interactive)
!   (let* ((hash (rails-ws:last-parameters))
! 	(action-name (gethash "action" hash))
! 	(controller-name (gethash "controller" hash)))
!     (if (and action-name controller-name)
! 	(rails-controller-layout:switch-to-action-in-controller controller-name action-name)
!       (message "Parameters not found"))))
! 
! (provide 'rails-ws)

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-02-06 21:16
Sender: Perry Smith

Sorry.  The code above is for the wrong feature.  The attached
code is the right
code.

Attached Files:

Name Description Download
B Download

Changes:

Field Old Value Date By
File Added3323: B2008-02-06 21:16pedz