Re: emacs / distel problem with dynamic tags

"Bill Clementson" <[email protected]> Thu, 5 Jul 2007 00:14:48 -0700
Newsgroups gmane.comp.lang.erlang.distel.devel
Message-ID <[email protected]>
Hi Matthias,

On 7/4/07, [email protected] <[email protected]> wrote:
> "Bill Clementson" <[email protected]> writes:
>
> > On 7/4/07, [email protected] <[email protected]> wrote:
> >> In other words, the old behaviour of "C-u M-x
> >> erl-find-source-under-point" is identical to the (old and new) behaviour
> >> of "M-x erl-find-mod".
> >>
> >> Actually, that's not quite true. C-u M-x erl-find-source-under-point
> >> defaults the selection to the module/function under the point, whereas
> >> erl-find-mod does not. Also, erl-find-mod is not bound to a convenient
> >> key sequence.
> >
> > Yes, in fact I didn't realize it even existed before you commented on
> > it. [...] I had the feeling that there might be "legacy code" reasons
> > for it being in distel as its functionality seems to have been
> > subsumed by erl-find-source-under-point.
>
> The two commands are indeed very similar.
>
> > Actually, the default that is displayed when you do "C-u M-." is m:f/a
> > (where the "a" is the arity). Since I'm still a newbie at erlang, I
> > frequently press "C-u M-." on a function and specify a different "a"
> > value. I don't know if this is common or not; however, I seem to do it
> > on a regular basis.
>
> That is a reasonable use case.
>
> > My personal preference (at the moment), would be a) as I would almost
> > always have switched to the node that I would be doing the "C-u M-."
> > lookup on prior to my doing the command. However, this is probably due
> > to my erlang newbie status and I would probably find that I do want to
> > do source lookups on other nodes in the future. However (when I
> > consider how I usually use "M-."), I might be quite happy with a) even
> > once I'm more accomplished with erlang since the need to press ENTER
> > on the node for c) is compounded when you're doing multiple m:f/a
> > lookups. For example, I will often do multiple source lookups on
> > functions with different arities as I drill down into functions that
> > are called by the function that I initially go to. And, once I've
> > changed the node, I no longer have to specify the node again on
> > subsequent searches whereas with c) I would have to press ENTER at the
> > node prompt each time.
>
> ok. Let's stick with a) (the old behaviour) then, until enough people
> complain about the inconsistency. Currently it's just me ;)

It may be just you, but you are quite persuasive! ;-)

> > Option b) and d) are probably bad choices as they negatively impact
> > users who are accustomed to using "C-u M-." as it existed before the
> > mods. I don't really like the idea of having multiple key bindings
> > (nor multiple commands) for source lookup. So, I guess that (if I had
> > to pick only one option) I would select a) and eliminate erl-find-mod
> > altogether. However, I guess that other people might be using
> > erl-find-mod as well, so eliminating erl-find-mod probably isn't an
> > option. For the same reason (e.g. - other people are used to using
> > "C-u M-." to specify a m/f/a for a source lookup), options b) and d)
> > probably aren't good options.
>
> We should not worry about backwards compatibility too much. The distel
> user base is quite small and in any case folks who desperately want the
> old behaviour back can just engage in some minor elisp hackery to do so.
>
> So let's get rid of erl-find-mod.

Works for me!

> > However, I like the mod you made to erl-target-node and it is good to
> > try to keep behaviour consistent (although an argument could be made
> > that the prefix arg node selection functionality should only apply to
> > distel functions that have "node" as an argument and erl-find-source
> > does not have "node" as an argument and it has always done a search on
> > the current node). So, option c) would be the option that I would most
> > favour if you feel that it is still a good idea to do prefix arg node
> > selection with "C-u M-.".
>
> Option c), node name defaulting and history, would be a valuable
> addition in any case. I won't have time to work on this over the next
> few days, but if yo want to have a go just take a look at the elisp docs
> for read-string as a starting point.

I've attached a patch below that I think does what you wanted (it
removes erl-find-mod and adds node name defaulting and history). Let
me know if it looks ok to you.

-- 
Bill Clementson

Index: elisp/erl-service.el
===================================================================
--- elisp/erl-service.el	(revision 30)
+++ elisp/erl-service.el	(working copy)
@@ -20,6 +20,9 @@
   "The name of the node most recently contacted, for reuse in future
 commands. Using C-u to bypasses the cache.")

+(defvar erl-nodename-history nil
+  "The historical list of node names that have been selected.")
+
 (defun erl-target-node ()
   "Return the name of the default target node for commands.
 Force node selection if no such node has been choosen yet, or when
@@ -43,11 +46,20 @@
 (defun erl-choose-nodename ()
   "Prompt the user for the nodename to connect to in future."
   (interactive)
-  (let* ((name-string (read-string "Node: "))
+  (let* ((nodename-string (if erl-nodename-cache
+			      (symbol-name erl-nodename-cache)
+			    nil))
+	 (name-string (read-string (if nodename-string
+				       (format "Node (default %s): "
+					       nodename-string)
+				     "Node: ")
+				   nil
+				   'erl-nodename-history
+				   nodename-string))
          (name (intern (if (string-match "@" name-string)
                            name-string
-                         (concat name-string
-                                 "@" (erl-determine-hostname))))))
+			 (concat name-string
+				 "@" (erl-determine-hostname))))))
     (when (string= name-string "")
       (error "No node name given"))
     (setq erl-nodename-cache name)
@@ -731,23 +743,6 @@
   (apply #'erl-find-source
          (or (erl-read-call-mfa) (error "No call at point."))))

-(defun erl-find-mod (modstr)
-  "goto source code of mfa. mfa can be m, m:f or m:f/a.
-Similar to erl-find-source-under-point, but prompts user for mfa."
-  (interactive (list (read-string "Module: ")))
-  (let* ((mcolon (split-string modstr ":"))
-         (mslash (case (length mcolon)
-                   (1 nil)
-                   (2 (split-string (cadr mcolon) "/"))))
-         (mod (car mcolon))
-         (fun (if mslash
-                  (car mslash)
-                nil))
-         (ari (if (eq 2 (length mslash))
-                  (string-to-number (cadr mslash))
-                nil)))
-    (apply #'erl-find-source (list mod fun ari))))
-
 (defun erl-find-source-unwind ()
   "Unwind back from uses of `erl-find-source-under-point'."
   (interactive)

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/