help-gnu-emacs
[Top][All Lists]
Advanced

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

How can avoid "assignment to free variable" warning?


From: Lele Gaifax
Subject: How can avoid "assignment to free variable" warning?
Date: Tue, 15 Apr 2014 01:43:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

Hi all,

while I'm almost satisfied by my current implementation[#] of the solution
to the problem of editing a HTML template embedded in Javascript code,
when I compile it I get:

  In eet/edit:
  esk/js.el:154:32:Warning: assignment to free variable `eet/original-buffer'
  esk/js.el:155:52:Warning: assignment to free variable `eet/original-start'
  esk/js.el:156:50:Warning: assignment to free variable `eet/original-end'
  esk/js.el:157:51:Warning: assignment to free variable `eet/original-line'
  esk/js.el:158:32:Warning: assignment to free variable `eet/original-winconf'

  In eet/abort:
  esk/js.el:192:18:Warning: reference to free variable `eet/original-winconf'
  esk/js.el:193:26:Warning: reference to free variable `eet/original-buffer'
  esk/js.el:194:24:Warning: reference to free variable `eet/original-line'

In eet/edit, I used the following code to store some information I need
into buffer's local variables:

  (defun eet/edit (start end current-line)
    "Extract the template from the array of strings into a new buffer."
    (let ((template (buffer-substring-no-properties start end))
          (original-buffer (current-buffer))
          (winconf (current-window-configuration)))
      (switch-to-buffer (generate-new-buffer "*template-edit*"))
      (delete-other-windows-internal)
      (insert template)
      (eet/implode)
      (set-buffer-modified-p nil)
      (goto-char (point-min))
      (when (looking-at "<")
        (html-mode))
      (eet/mode 1)
      (set (make-local-variable 'eet/original-buffer) original-buffer)
      (set (make-local-variable 'eet/original-start) start)
      (set (make-local-variable 'eet/original-end) end)
      (set (make-local-variable 'eet/original-line) current-line)
      (set (make-local-variable 'eet/original-winconf) winconf)
      (message "Type C-c C-c to confirm changes, C-c C-k to abort")))

while eet/abort uses some of those to restore the original state:

  (defun eet/abort ()
    "Used in template-edit-mode to close the popup window."
    (interactive)
    (let ((winconf eet/original-winconf)
          (original-buffer eet/original-buffer)
          (original-line eet/original-line))
      (kill-buffer)
      (set-window-configuration winconf)
      (switch-to-buffer original-buffer)
      (goto-char (point-min))
      (forward-line original-line)))

Should I worry about the warnings? Am I doing it wrongly in some way? Is
there a better approach to store that info that would keep the compiler
happy? 

Thanks in advance for any hints,
ciao, lele.

[#] see http://hub.darcs.net/lelit/emacs-starter-kit/browse/esk/js.el#70
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]