Chitale, Sandip V writes:
> Interesting....
>
> I have:
>
> tempo-insert-region's value is nil
> transient-mark-mode's value is t
>
> If I have a region around -
>
> x = x/0;
>
> and then type -
>
> M-x jde-gen-try RET Throwable RET
>
> I get -
>
> try {
> x = x/0;|
> } catch (Throwable e) {
>
> }
>
> with cursor where | is.
>
> My original question was can I avoid
>
> M-x jde-gen-try RET Throwable RET
>
> and simply type t r y SPC with region around -
>
> x = x/0;
>
> and get the same behaviour as above.
>
> Any thoughts?
I verified that the cflow templates do indeed work if you execute them
directly but not if you invoke them via abbrev mode expansion. I do
not know if there is a way to get them to work when invoked via
abbrev-mode expansion. If not, I could write a set of "wrapper"
functions that locally set tempo-insert-region on and then invoke the
corresponding template, e.g.,
(defun jde-wrap-if ()
(interactive)
(let ((tempo-insert-region t))
(jde-gen-if)))
- Paul
>
> sandip
>
> -----Original Message-----
> From: Paul Kinnucan [mailto:[EMAIL PROTECTED]
> Sent: Monday, August 04, 2003 11:17 AM
> To: Chitale, Sandip V
> Cc: Paul Kinnucan; JDE Users
> Subject: RE: Useful helper functions
>
>
> Chitale, Sandip V writes:
> > Paul,
> >
> > Actually I have a question about region based cflow templates. How do
> I > use them? >
> > I ask because, with region, as soon as I type first letter of 'if' or
> > 'try' the mark (region) is deactivated. >
> > Or the only way to use the functionality is by marking a region and
> then > doing one of: >
> > 1. M-x jde-gen-try-catch-wrapper RET
> > 2. Bing the function to some key or menu and use that keystroke/menu
> > selection >
> > Am I missing something here?
> >
>
> No. The cflow templates do not currently support wrapping
> a region in a cflow construct. The try-catch, if-then, etc. templates do
> include a tempo region element so it appears that the author's intention
> was to support region wrapping. To activate this requires setting
> tempo-insert-region to a nonnil value. However, when I try this with the
> if-then template, the template simply deleted the region and generates
> the final brace above the if line. There seems to be a bug in the
> template or tempo. I will look into this further and try to get the
> templates to wrap themselves around a region
> if a region is selected.
>
> Paul
>
> > cheers,
> > sandip
> >
> > > -----Original Message-----
> > > From: Paul Kinnucan [mailto:[EMAIL PROTECTED]
> > > Sent: Monday, August 04, 2003 9:45 AM
> > > To: Nascif Abousalh-Neto
> > > Cc: Robert Mecklenburg; JDE Users
> > > Subject: RE: Useful helper functions
> > >
> > >
> > > Nascif Abousalh-Neto writes:
> > > > Cool stuff, thanks for sharing.
> > > >
> > > > Would there be a way to implement the try/catch wrapper
> > > with a more precise > catch statement? I guess it would
> > > require some introspection on the method > calls inside the
> > > region. Is that information easily available somewhere in >
> > > JDEE, say in the new xref database? >
> > >
> > > The JDEE already includes a function for wrapping a region > > in
> a try-catch form. See the doc string for
> > > jde-gen-try-catch-wrapper. It does not try to guess the
> > > exception that you want to catch.
> > >
> > > - Paul
> > >
> > >
> > > > Regards,
> > > > Nascif
> > > >
> > > > > -----Original Message-----
> > > > > From: Robert Mecklenburg [mailto:[EMAIL PROTECTED]
> > > > > Sent: Monday, July 28, 2003 12:31 AM
> > > > > To: JDE Users
> > > > > Subject: Useful helper functions
> > > > >
> > > > >
> > > > > Here is some code I've written that seems useful here.
> > > > > Include it in JDEE if you feel any are worthy. There's quite
> > > > > a span of time represented by these so some use more or less
> > > > > advanced features as my understanding evolved. If you'd like
> > > > > me to rework them for jdee, give me specific poniters and
> > > > > I'll resubmit with changes.
> > > > >
> > > > >
> ================================================================
> > > > >
> > > > > (defun insert-fully-qualified-name (name)
> > > > > "Transform the class name at point into a fully qualified
> > > > > name. This is useful when writing @{link name} and name is
> > > > > not in the import list."
> > > > > (interactive (list (read-string "Class name: "
> > > > > (thing-at-point 'word))))
> > > > > (save-excursion
> > > > > (save-window-excursion
> > > > > (let* ((full-name
> > > (jde-parse-select-qualified-class-name name)))
> > > > > (if (not (looking-at "\\<"))
> > > > > (forward-word -1))
> > > > > (kill-word 1)
> > > > > (insert-before-markers full-name)))))
> > > > >
> > > > >
> > > > > (defun make-word-a-link ()
> > > > > "Transform the class name at point into a javadoc @link. If
> > > > > the class name does not occur in the current package insert
> > > > > the fully qualified name, too."
> > > > > (interactive)
> > > > > (if (not (looking-at "\\<"))
> > > > > (forward-word -1))
> > > > > (insert "[EMAIL PROTECTED] ")
> > > > > (let ((word (buffer-substring (point) (save-excursion
> > > > > (forward-word 1) (point)))))
> > > > > (if (not (file-exists-p (concat word ".java")))
> > > > > (progn
> > > > > (insert-fully-qualified-name word)
> > > > > (insert " " word)))
> > > > > (insert "}")))
> > > > >
> > > > >
> ================================================================
> > > > >
> > > > > (defun wrap-region-in-try-catch (start end)
> > > > > (interactive "r")
> > > > > (save-excursion
> > > > > (goto-char start)
> > > > > (beginning-of-line)
> > > > > (let (region-ends-with-newline (e (make-marker)))
> > > > > (set-marker e end)
> > > > > (insert "try\n{\n")
> > > > > (goto-char e)
> > > > > (setq region-ends-with-newline (eolp))
> > > > > (if region-ends-with-newline
> > > > > (insert "\n"))
> > > > > (insert "}\ncatch ( Exception error )\n{\n}")
> > > > > (if (not region-ends-with-newline)
> > > > > (insert "\n"))
> > > > > (set-marker e (point))
> > > > > (goto-char start)
> > > > > (forward-line -2)
> > > > > (c-indent-region (point) e))))
> > > > >
> > > > >
> ================================================================
> > > > >
> > > > > (defun jde-run-with-arguments (arg)
> > > > > "Run the class in the current buffer. If a prefix argument
> > > > > is given, prompt for different command line arguments and
> > > > > remember them for subsequent runs."
> > > > > (interactive "P")
> > > > > (if arg
> > > > > (jde-run-set-app-args (read-string "Enter arguments:
> ")))
> > > > > (jde-run nil))
> > > > >
> > > > >
> ================================================================
> > > > >
> > > > > (defun jde-replace-in-defun (old-word new-word)
> > > > > "Replace the word under the cursor within the current method."
> > > > > (interactive
> > > > > (list (read-string "Query replace: " (car
> > > > > (semantic-ctxt-current-symbol)))
> > > > > (read-string "Replace with: ")))
> > > > > (senator-mark-defun)
> > > > > (perform-replace old-word new-word t nil t nil nil
> > > (point) (mark)))
> > > > >
> > > > >
> ================================================================
> > > > >
> > > > > ;;; This uses the hash method from Josh Bloch's Effective
> > > > > Java Programming. (jde-gen-define-abbrev-template
> > > "hash-code-method"
> > > > > '("private int hashCode()" '> 'n
>
> > > > > "{" '>'n
> > > > > "int result = 17;" '>'n
> > > > > "result = result * 37 + /*
> > > > > data member */;" '>'n
> > > > > "/* Add more result lines
> > > > > here */" '>'n
> > > > > "return result;" '>'n
> > > > > "}" '>))
> > > > >
> > > > > (jde-gen-define-abbrev-template "equals-method"
> > > > > '("private boolean equals(
> > > > > Object o )" '> 'n
> > > > > "{" '>'n
> > > > > "if ( this == o )" '>'n
> > > > > "{" '>'n
> > > > > "return true;" '>'n
> > > > > "}" '>'n '>'n
> > > > > "if ( ! ( o instanceof "
> > > > > (file-name-sans-extension
> > > > > (file-name-nondirectory
> > > > > buffer-file-name))
> > > > > " ) )" '>'n
> > > > > "{" '>'n
> > > > > "return false;" '>'n
> > > > > "}" '>'n '>'n
> > > > > (file-name-sans-extension
> > > > > (file-name-nondirectory
> > > > > buffer-file-name))
> > > > > " "
> > > > > (downcase
> > > > > (substring
> (file-name-sans-extension
> > > > >
> > > > > (file-name-nondirectory buffer-file-name)) 0 1))
> > > > > " = ("
> > > > > (file-name-sans-extension
> > > > > (file-name-nondirectory
> > > > > buffer-file-name))
> > > > > ") o;" '>'n '>'n
> > > > > "/* Test class members here.
> > > > > */" '>'n '>'n
> > > > > "return true;" '>'n
> > > > > "}" '>))
> > > > >
> > > > >
> > > > > Cheers,
> > > > > --
> > > > > Robert
> > > > >
> > > > >
> > >
> > >