[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Search]

Re: elisp question



   Our company wants to have on-line code reviews to increase productivity.
   Want we need is a macro ...

Why not write a function in Emacs Lisp instead?  The advantage of a
function is that it is easier to read, understand, and change than a
keyboard macro.  

I have written a function that does as you ask.  

As written, it inserts only the user's login name.  However, I also
provide what I think is a better alternative, which is to insert the
user's full name and then his or her login name and the system name,
as in an email header.  If you want to use this alternative, comment
out the line that inserts the short form and uncomment the lines that
insert the longer identification string.

When invoked with the cursor in line three,
the function converts the following three lines from this:

    Line one.
    Line two.
    Line three.

to this:

    Line one.
    Line two.
    /* ### bob


    */
    Line three.


--- begin code ---

;;; Insert a code review comment template.

(defun code-review-comment ()
  "Create a code review comment.

Open a blank line above the line where point is currently, 
insert a /* opening comment delimiter in that line, 
insert three # signs, and 
insert the user's login name.

Then insert two blank lines and 
an ending comment delimiter */ on a third line.  

Then place the currsor on the line above the end comment delimiter."
  (interactive)
  (let ((identification-string 
         ;; Short form
         (format "%s" (user-login-name))
         ;; Long form; insert identification with this format:
         ;; Robert J. Chassell <bob@xxxxxxxxxxx>
         ;; To use, comment out the preceding format line and
         ;; uncomment the two following lines:
         ;; (format "%s <%s@%s>" 
         ;;         (user-full-name) (user-login-name) (system-name))
         ))
    (beginning-of-line)
    (insert "/* ### ")
    (insert identification-string)
    (insert "\n\n\n")
    (insert "*/\n")
    (forward-line -2)))

;; Bind macro code-review-comment to control-c control-r.

(global-set-key "\C-c\C-r" 'code-review-comment)

--- end code ---



   This macro will be loaded from a shell script by invoking emacs
   with the -l option ...

Why do you need to do this?  Won't the people inserting the code
review comment be using Emacs?


As for running Emacs as a shell script: some systems let you place

    #!/usr/bin/emacs

at the beginning of a script written in Emacs Lisp.

Other systems are more limited; in that case you would need to run
Emacs in batch mode in a shell script that runs a different
interpreter, such as bash.  I think that using Emacs this way is a bad
idea.  You would be better off writing a short C Shell or Bourne Again
shell script to insert your text directly.  But if you do want to do
this, see your documenation in the Emacs manual, 
File: emacs, Node: Command Example

Best wishes

-- 

    Robert J. Chassell                  bob@xxxxxxxxxxx
    Rattlesnake Enterprises             http://www.rattlesnake.com

-----------------------------------------------------------------------------
       To unsubscribe or change your address send mail to
"emacspeak-request@xxxxxxxxxxx" with a subject of "unsubscribe" or "help"


Emacspeak Files | Subscribe | Unsubscribe