From: Eric Lilja <mindcooler@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Why didn't setq work here?
Date: Fri, 07 Jan 2011 13:43:47 +0100 [thread overview]
Message-ID: <ig71q8$cii$1@dough.gmane.org> (raw)
In-Reply-To: <AANLkTimxqtvOvoF_khQUBVAgQ5SxZF6nkuNS1VspbTZD@mail.gmail.com>
On 2011-01-07 04:40, Deniz Dogan wrote:
> 2011/1/7 Eric Lilja<mindcooler@gmail.com>:
>> Hello, I'm running "GNU Emacs 24.0.50.1 (i386-mingw-nt6.1.7600) of
>> 2011-01-03 on 3249CTO" (a build provided by Mr Sean Sieger) under Windows 7
>> x64.
>>
>> I don't really know how to configure emacs so please excuse any stupidity
>> found below and improper use terminology.
>>
>> For LaTeX buffers, I wanted to turn on the minor mode auto-fill-mode, with a
>> fill-column of 76.
>>
>> After a bit of investigating, I found that I could run "commands" (if that's
>> what they're called) when major mode latex is loaded/activated for a buffer
>> by using hooks, like this:
>>
>> (defun my-latex-hook ()
>> (message "Running my-latex-hook")
>> )
>> (add-hook 'latex-mode-hook 'my-latex-hook)
>>
>> I added the statement above and launched emacs like this:
>> $ emacs foo.tex&
>> and I could see from the message output that my hook was indeed working.
>> Good. Just what I wanted.
>>
>> So now I just need to turn on the minor mode auto-fill-mode with fill-column
>> set to 76 when this hook is "executed".
>>
>> In my naivety, I tried this:
>>
>> (defun my-latex-hook ()
>> (message "Running my-latex-hook")
>> (setq auto-fill-mode 1)
>> (setq fill-column 76)
>> )
>> (add-hook 'latex-mode-hook 'my-latex-hook)
>>
>> I saw a warning when I byte-compiled my .emacs:
>> In my-latex-hook:
>> .emacs:42:9:Warning: assignment to free variable `auto-fill-mode'
>>
>> but tried anyway. Closed emacs and restarted as I did above ($ emacs
>> foo.tex&)
>>
>> I noticed straight away that the minor mode auto-fill-mode had not been
>> turned on.
>> However, C-h v fill-column showed that my fill-column had been set though
>> since its value was now the desired 76 instead of the default 70.
>>
>> In order to solve the problem of auto-fill-mode not being turned on and
>> getting rid of the byte compiler warning, I rewrote my hook like this:
>>
>> (defun my-latex-hook ()
>> (message "Running my-latex-hook")
>> (auto-fill-mode 1)
>> (set-fill-column 76)
>> )
>> (add-hook 'latex-mode-hook 'my-latex-hook)
>>
>> Now auto-fill-mode is indeed turned on and I don't get a warning by the byte
>> compiler when I set fill column. Ok, so I am happy. Problem solved! :)
>>
>> But here's my question: Why didn't setq work as I thought it would? By not
>> work I meant I the minor mode auto-fill-mode was not turned on and even
>> though the fill column was set as I desired, the statement produced a
>> warning as I showed above.
>>
>> Thanks for any replies! :)
>>
>> - EL
>>
>>
>>
>
> `setq' only sets the value of a variable. The variable you tried to
> set, auto-fill-mode, has not been defined -- it doesn't "exist" yet.
> The warning about a "free variable" in this context means that the
> variable is not defined in the current scope.
>
> The correct way to turn auto-fill-mode on or off is to call the
> function with the same name, which you figured out later. The
> _variable_ auto-fill-mode doesn't exist in this case, though in many
> other modes there is a variable named identically to the function to
> turn it on or off. In some modes where that is the case, setting the
> variable has effect. In some other modes, it doesn't.
>
> By the way, in Emacs a function is a function and a "command" is a
> function that can be called interactively, i.e. using e.g. M-x.
>
> I hope that makes things a bit clearer.
>
> --
> Deniz Dogan
>
>
Hello Mr Dogan, and thank you for your polite and informative reply.
Using your information, I added the following comment to my .emacs:
(defun my-latex-hook ()
(message "Running my-latex-hook")
;; Using setq does not work, because setq is for setting values of
;; variables and there is no variable called auto-fill-mode (as can
;; be observed by performing C-h v auto-fill-mode). The correct way
;; to turn on auto-fill-mode is to call the funcion auto-fill-mode
;; with a positive argument. In some modes there exists a variable
;; with the same name as the function which disables or enables that
;; mode (a variable that can be used for the same purpose), but
;; auto-fill-mode is not one of those modes.
(auto-fill-mode 1)
(set-fill-column 76)
)
(add-hook 'latex-mode-hook 'my-latex-hook)
I have one final question though. fill-column does seem to be a
variable. It can be described using C-h v and set using M-x
set-variable. However, if I replace (set-fill-column 76) with (setq
fill-column 76) the variable value is never changed (and no byte
compiler warning btw). I see now that I was mistaken in my first post,
btw, I thought that using setq worked for fill-column but produced a
warning, but this is not the case. It didn't work and the byte compiler
warning was for auto-fill-mode.
So my final question, before I can lay this entire topic to rest, is:
why didn't setq work for fill-column, which seems to satisfy the
requirements of being a variable?
Thanks!
- EL
next prev parent reply other threads:[~2011-01-07 12:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-07 2:05 Why didn't setq work here? Eric Lilja
2011-01-07 3:40 ` Deniz Dogan
2011-01-07 12:43 ` Eric Lilja [this message]
2011-01-07 14:26 ` Tassilo Horn
2011-01-07 16:05 ` Eric Lilja
2011-01-07 16:59 ` Peter Dyballa
2011-01-08 17:29 ` Tassilo Horn
[not found] ` <mailman.6.1294416372.29236.help-gnu-emacs@gnu.org>
2011-01-07 22:50 ` Tim X
[not found] <mailman.23.1294365997.1330.help-gnu-emacs@gnu.org>
2011-01-07 2:54 ` Pascal J. Bourguignon
2011-01-07 3:50 ` rusi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='ig71q8$cii$1@dough.gmane.org' \
--to=mindcooler@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.