convention for unused variables

Vlad Dumitrescu vlad_dumitrescu@REDACTED
Thu Oct 14 15:21:08 CEST 2004


I have a dirty solution for that.

Sorry, I have no patch file, but on the other hand it's just a couple of
additions. See the end of the mail.

* In order to run Distel with R10, the erlang node needs to be started with a
+R9 flag - you can either hack erlang-start.el, or use a manually started node.

* Compile distel.erl to distel/ebin and also el-service.el (if needed). I think
emacs should be restarted.

* Use M-x erl-check-undefined-vars to initialize the warnings list
* Use M-x erl-next-undef to go to the position of the undefined variable

* The warnings list is *global*, so if you go to another buffer, it needs to be
regenerated with erl-check-undefined-vars !!

There's no advanced error checking, so use at your own risk. Maybe later I could
get some support from Luke to make it right in order to add it to the mainstream

Hope it helps.

Add at end of el-service.el:
;; -----------------------

(defun erl-check-undefined-vars ()
  "Compiles the file and returns warnings for undefined variables."
  (let* ((node (erl-read-nodename))
  (file (buffer-file-name))
   (erl-rpc #'erl-check-undefined-vars-1 '()
     node 'distel 'check_undefined_vars (list file)

(defun erl-check-undefined-vars-1 (warns)
  (setq *erl-undef-vars* warns)
  (cond (warns
  ;;(local-set-key "\C-c\C-dn" erl-next-undef)

(defun erl-next-undef()
  (let ((warn (pop *erl-undef-vars*))
    ;(insert (format "%s" warn))
    (cond (warn
    (goto-line (car warn))
    (let ((case-fold-search nil)) (search-forward (format "%s" (cadr warn))))
    (message (format "Undefined var: %s" (cadr warn)))
    ;;(local-unset-key "\C-c\C-dn")
    (message "No more warnings in file. Run erl-check-undefined-vars again.")

Add at end of distel.erl:
%% -------------------------------------------------------

check_undefined_vars(File) ->
    [{_F, Warns}|_] = case compile:file(File, [binary, return_warnings]) of
  {ok, _Mod, _B, W} -> W;
  {error, _E, W} -> W;
  _ -> []
    Unused = [fmt_unused(X) || X <- Warns, is_unused(X)],

is_unused({L, M, {unused_var, V}}) ->

fmt_unused({L, M, {unused_var, V}}) ->
    [L, V].
%% ------------------------------------------

More information about the erlang-questions mailing list