* enable-local-variables
@ 2007-01-01 20:04 Eric Twietmeyer
2007-01-01 20:43 ` enable-local-variables Leo
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Eric Twietmeyer @ 2007-01-01 20:04 UTC (permalink / raw)
Hi,
I just upgraded to emacs 22.0.92.1. I write C++ code and there is a
local variable "typedefs" that is used for syntax highlighting. Now
that I have upgraded I find that every buffer I open that has this
local variable "typedefs" in it I am presented with a dialog asking
that I confirm that the local variable is "safe".
I have read through the docs that I can find on this, and I realized
that I can set the "enable-local-variables" value to ":all", and now it
won't ask me any more about these typedefs. The docs say "don't do
this" (i.e. use the ":all" value) because it is globally unsafe.
However, there doesn't appear to be any way to specify that the local
variable "typedefs" should always be accepted as safe, regardless of
its values. Each C++ file I visit will have a different value of
"typedefs", so I can't in any reasonable way create a var, val cons
list of safe values. It would be thousands of entries long.
So is there another way to work around this? I never have any other
local variables defined in my files, I use emacs purely for writing
code. I guess I'm just wondering what the expected usage would be in
this case.
Thanks,
-Eric Twietmeyer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-01 20:04 enable-local-variables Eric Twietmeyer
@ 2007-01-01 20:43 ` Leo
2007-01-01 21:45 ` enable-local-variables Ralf Angeli
[not found] ` <mailman.2620.1167684196.2155.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 10+ messages in thread
From: Leo @ 2007-01-01 20:43 UTC (permalink / raw)
* Eric Twietmeyer (2007-01-01 12:04 -0800) said:
^^^^^^^^^^^^^^^
> Hi,
>
> I just upgraded to emacs 22.0.92.1. I write C++ code and there is a
> local variable "typedefs" that is used for syntax highlighting. Now
> that I have upgraded I find that every buffer I open that has this
> local variable "typedefs" in it I am presented with a dialog asking
> that I confirm that the local variable is "safe".
If you answer '!', it will be saved to your custom file.
--
Leo <sdl.web AT gmail.com> (GPG Key: 9283AA3F)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-01 20:04 enable-local-variables Eric Twietmeyer
2007-01-01 20:43 ` enable-local-variables Leo
@ 2007-01-01 21:45 ` Ralf Angeli
2007-01-01 22:27 ` enable-local-variables Eric Twietmeyer
[not found] ` <mailman.2620.1167684196.2155.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2007-01-01 21:45 UTC (permalink / raw)
* Eric Twietmeyer (2007-01-01) writes:
> I just upgraded to emacs 22.0.92.1. I write C++ code and there is a
> local variable "typedefs" that is used for syntax highlighting. Now
> that I have upgraded I find that every buffer I open that has this
> local variable "typedefs" in it I am presented with a dialog asking
> that I confirm that the local variable is "safe".
[...]
> However, there doesn't appear to be any way to specify that the local
> variable "typedefs" should always be accepted as safe, regardless of
> its values. Each C++ file I visit will have a different value of
> "typedefs", so I can't in any reasonable way create a var, val cons
> list of safe values. It would be thousands of entries long.
You can specify a function as a symbol property for the variable. The
function is supposed to check if the values given to the variable have
the correct type. Since you didn't write which kind of values are
supposed to be assigned to the variable, it is not possible to give a
specific advice.
I'd also be interested in knowing which package or code uses the
variable before giving you a means to shoot yourself in the foot.
--
Ralf
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
[not found] ` <mailman.2620.1167684196.2155.help-gnu-emacs@gnu.org>
@ 2007-01-01 22:21 ` Eric Twietmeyer
0 siblings, 0 replies; 10+ messages in thread
From: Eric Twietmeyer @ 2007-01-01 22:21 UTC (permalink / raw)
Leo wrote:
> * Eric Twietmeyer (2007-01-01 12:04 -0800) said:
> ^^^^^^^^^^^^^^^
> > Hi,
> >
> > I just upgraded to emacs 22.0.92.1. I write C++ code and there is a
> > local variable "typedefs" that is used for syntax highlighting. Now
> > that I have upgraded I find that every buffer I open that has this
> > local variable "typedefs" in it I am presented with a dialog asking
> > that I confirm that the local variable is "safe".
>
> If you answer '!', it will be saved to your custom file.
>
> --
> Leo <sdl.web AT gmail.com> (GPG Key: 9283AA3F)
I have done this of course, but it didn't seem to do anything. When I
closed emacs and then restarted (I use the .emacs.desktop file to save
state), all of the same visited files resulted in the same question.
Since I keep many dozens of open files at a time, this means hitting
"!" several dozen times each time I start emacs. Even if this were
working correctly (which custom file should it be creating?), I fear
that the overhead of parsing this each time I visit a buffer would lead
to high overhead.
Anyway, there is never a need to query about this "typedefs" local
variable. It is always safe, regardless of its value.
Thanks,
-Eric Twietmeyer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-01 21:45 ` enable-local-variables Ralf Angeli
@ 2007-01-01 22:27 ` Eric Twietmeyer
2007-01-01 22:50 ` enable-local-variables Ralf Angeli
0 siblings, 1 reply; 10+ messages in thread
From: Eric Twietmeyer @ 2007-01-01 22:27 UTC (permalink / raw)
Ralf Angeli wrote:
> * Eric Twietmeyer (2007-01-01) writes:
>
> > I just upgraded to emacs 22.0.92.1. I write C++ code and there is a
> > local variable "typedefs" that is used for syntax highlighting. Now
> > that I have upgraded I find that every buffer I open that has this
> > local variable "typedefs" in it I am presented with a dialog asking
> > that I confirm that the local variable is "safe".
> [...]
> > However, there doesn't appear to be any way to specify that the local
> > variable "typedefs" should always be accepted as safe, regardless of
> > its values. Each C++ file I visit will have a different value of
> > "typedefs", so I can't in any reasonable way create a var, val cons
> > list of safe values. It would be thousands of entries long.
>
> You can specify a function as a symbol property for the variable. The
> function is supposed to check if the values given to the variable have
> the correct type. Since you didn't write which kind of values are
> supposed to be assigned to the variable, it is not possible to give a
> specific advice.
>
> I'd also be interested in knowing which package or code uses the
> variable before giving you a means to shoot yourself in the foot.
>
> --
> Ralf
Here is what the text looks like at the bottom of a typical C++ file I
edit:
/*
Local Variables:
typedefs:("boost" "noncopyable" "shared_ptr" "size_t" "std" "string"
"tCursorIPtr" "tDestroyI" "tEndian" "tStreamI" "tStreamIPtr" "wchar_t"
"wstring")
End:
*/
So the value of "typedefs" is just a list of quoted symbols. This list
changes from file to file. It is used by the syntax highlighting code
in C/C++ mode.
The question therefore remains, what can I do so that all such values
of typedefs are always considered "safe". I'm not certain why this is
being flagged in the first place, as the documentation I saw about
ricky variables indicates that their name should end in some special
characters, and my typedefs do not end in such characters. So I have
been confused from the start why this is marked as risky in the first
place and therefore why I am being queried about it each time I open
the file.
Thanks again,
-Eric Twietmeyer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-01 22:27 ` enable-local-variables Eric Twietmeyer
@ 2007-01-01 22:50 ` Ralf Angeli
2007-01-02 0:21 ` enable-local-variables Eric Twietmeyer
0 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2007-01-01 22:50 UTC (permalink / raw)
* Eric Twietmeyer (2007-01-01) writes:
> Ralf Angeli wrote:
>>
>> I'd also be interested in knowing which package or code uses the
>> variable before giving you a means to shoot yourself in the foot.
>
> Here is what the text looks like at the bottom of a typical C++ file I
> edit:
>
> /*
> Local Variables:
> typedefs:("boost" "noncopyable" "shared_ptr" "size_t" "std" "string"
> "tCursorIPtr" "tDestroyI" "tEndian" "tStreamI" "tStreamIPtr" "wchar_t"
> "wstring")
> End:
> */
>
> So the value of "typedefs" is just a list of quoted symbols.
Then
(put 'typedefs 'safe-local-variable 'listp)
should work.
> This list
> changes from file to file. It is used by the syntax highlighting code
> in C/C++ mode.
I couldn't find anything regarding "typedefs" in Emacs' sources.
Which mode is this and who is maintaining it? Could you inform those
people that they should mark the variable as safe (in case it really
is) in their mode?
> The question therefore remains, what can I do so that all such values
> of typedefs are always considered "safe". I'm not certain why this is
> being flagged in the first place, as the documentation I saw about
> ricky variables indicates that their name should end in some special
> characters, and my typedefs do not end in such characters. So I have
> been confused from the start why this is marked as risky in the first
> place and therefore why I am being queried about it each time I open
> the file.
All unknown variables are considered risky in CVS Emacs.
--
Ralf
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-01 22:50 ` enable-local-variables Ralf Angeli
@ 2007-01-02 0:21 ` Eric Twietmeyer
2007-01-02 2:21 ` enable-local-variables Eric Twietmeyer
0 siblings, 1 reply; 10+ messages in thread
From: Eric Twietmeyer @ 2007-01-02 0:21 UTC (permalink / raw)
Ralf Angeli wrote:
> * Eric Twietmeyer (2007-01-01) writes:
>
> > Ralf Angeli wrote:
> >>
> >> I'd also be interested in knowing which package or code uses the
> >> variable before giving you a means to shoot yourself in the foot.
> >
> > Here is what the text looks like at the bottom of a typical C++ file I
> > edit:
> >
> > /*
> > Local Variables:
> > typedefs:("boost" "noncopyable" "shared_ptr" "size_t" "std" "string"
> > "tCursorIPtr" "tDestroyI" "tEndian" "tStreamI" "tStreamIPtr" "wchar_t"
> > "wstring")
> > End:
> > */
> >
> > So the value of "typedefs" is just a list of quoted symbols.
>
> Then
> (put 'typedefs 'safe-local-variable 'listp)
> should work.
>
> > This list
> > changes from file to file. It is used by the syntax highlighting code
> > in C/C++ mode.
>
> I couldn't find anything regarding "typedefs" in Emacs' sources.
> Which mode is this and who is maintaining it? Could you inform those
> people that they should mark the variable as safe (in case it really
> is) in their mode?
>
> > The question therefore remains, what can I do so that all such values
> > of typedefs are always considered "safe". I'm not certain why this is
> > being flagged in the first place, as the documentation I saw about
> > ricky variables indicates that their name should end in some special
> > characters, and my typedefs do not end in such characters. So I have
> > been confused from the start why this is marked as risky in the first
> > place and therefore why I am being queried about it each time I open
> > the file.
>
> All unknown variables are considered risky in CVS Emacs.
>
> --
> Ralf
Ok, now I understand the confusion. I didn't realize that my extended
.emacs had code I took long ago from someone that added this "feature",
I thought it was part of the standard font-lock stuff. Here is the
relevant code:
-------------------------------------------------------------------------------------------------------
;; Need to have a new variable to hold the typedefs for this buffer.
(defvar typedefs nil "Typedefs in this buffer.")
(make-variable-buffer-local 'typedefs)
;; Add the word at the current point to the list of typedefs. Insert
stuff
;; at bottom of file to save the information.
(defun make-word-into-typedef ()
"Take the word at the current point and make font-lock realize it's a
type.
The word will be added to the local variable list at the end of the
file."
(interactive)
(let ((this-type (current-word)))
(if (member this-type typedefs)
(message "%s is already a type" this-type)
;; Sort for niceness
(setq typedefs (sort (cons this-type typedefs) 'string<))
;; Find the typedefs line if we have one, and replace it
(save-excursion
(goto-char (point-min))
(if (re-search-forward "^typedefs:" nil 1)
(progn
(beginning-of-line)
(push-mark nil t t)
(end-of-line)
(delete-region (mark) (point)))
(progn
;; Break up the string so Emacs doesn't get confused when
;; reading this file
(insert "/*\nLocal ")
(insert "Variables:\n\nEnd:\n*/\n")
(forward-line -3)))
(insert "typedefs:")
(insert (prin1-to-string typedefs)))
(hack-local-variables)
(add-extra-type (make-regexp typedefs))
;; Reset font-lock
(font-lock-mode 0)
(font-lock-mode 1))))
;; Called to add the types when the hook executes.
(defun add-extra-type (new_type)
(setq c-font-lock-extra-types
(cons new_type c++-font-lock-extra-types))
(setq c++-font-lock-extra-types c-font-lock-extra-types)
)
Part of my c-mode-hook:
(if typedefs (add-extra-type (make-regexp typedefs)))
----------------------------------------------------------------------------------
So what do I need to do to make this typedef variable always safe? Or
where do I look in the docs to learn how to do this?
Thanks again for your help!
-Eric Twietmeyer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-02 0:21 ` enable-local-variables Eric Twietmeyer
@ 2007-01-02 2:21 ` Eric Twietmeyer
2007-01-02 6:56 ` enable-local-variables Ralf Angeli
0 siblings, 1 reply; 10+ messages in thread
From: Eric Twietmeyer @ 2007-01-02 2:21 UTC (permalink / raw)
Eric Twietmeyer wrote:
> Ralf Angeli wrote:
> > * Eric Twietmeyer (2007-01-01) writes:
> >
> > > Ralf Angeli wrote:
> > >>
> > >> I'd also be interested in knowing which package or code uses the
> > >> variable before giving you a means to shoot yourself in the foot.
> > >
> > > Here is what the text looks like at the bottom of a typical C++ file I
> > > edit:
> > >
> > > /*
> > > Local Variables:
> > > typedefs:("boost" "noncopyable" "shared_ptr" "size_t" "std" "string"
> > > "tCursorIPtr" "tDestroyI" "tEndian" "tStreamI" "tStreamIPtr" "wchar_t"
> > > "wstring")
> > > End:
> > > */
> > >
> > > So the value of "typedefs" is just a list of quoted symbols.
> >
> > Then
> > (put 'typedefs 'safe-local-variable 'listp)
> > should work.
> >
> > > This list
> > > changes from file to file. It is used by the syntax highlighting code
> > > in C/C++ mode.
> >
> > I couldn't find anything regarding "typedefs" in Emacs' sources.
> > Which mode is this and who is maintaining it? Could you inform those
> > people that they should mark the variable as safe (in case it really
> > is) in their mode?
> >
> > > The question therefore remains, what can I do so that all such values
> > > of typedefs are always considered "safe". I'm not certain why this is
> > > being flagged in the first place, as the documentation I saw about
> > > ricky variables indicates that their name should end in some special
> > > characters, and my typedefs do not end in such characters. So I have
> > > been confused from the start why this is marked as risky in the first
> > > place and therefore why I am being queried about it each time I open
> > > the file.
> >
> > All unknown variables are considered risky in CVS Emacs.
> >
> > --
> > Ralf
>
> Ok, now I understand the confusion. I didn't realize that my extended
> .emacs had code I took long ago from someone that added this "feature",
> I thought it was part of the standard font-lock stuff. Here is the
> relevant code:
>
> -------------------------------------------------------------------------------------------------------
>
> ;; Need to have a new variable to hold the typedefs for this buffer.
> (defvar typedefs nil "Typedefs in this buffer.")
> (make-variable-buffer-local 'typedefs)
>
> ;; Add the word at the current point to the list of typedefs. Insert
> stuff
> ;; at bottom of file to save the information.
> (defun make-word-into-typedef ()
> "Take the word at the current point and make font-lock realize it's a
> type.
> The word will be added to the local variable list at the end of the
> file."
> (interactive)
> (let ((this-type (current-word)))
> (if (member this-type typedefs)
> (message "%s is already a type" this-type)
> ;; Sort for niceness
> (setq typedefs (sort (cons this-type typedefs) 'string<))
> ;; Find the typedefs line if we have one, and replace it
> (save-excursion
> (goto-char (point-min))
> (if (re-search-forward "^typedefs:" nil 1)
> (progn
> (beginning-of-line)
> (push-mark nil t t)
> (end-of-line)
> (delete-region (mark) (point)))
> (progn
> ;; Break up the string so Emacs doesn't get confused when
> ;; reading this file
> (insert "/*\nLocal ")
> (insert "Variables:\n\nEnd:\n*/\n")
> (forward-line -3)))
> (insert "typedefs:")
> (insert (prin1-to-string typedefs)))
>
> (hack-local-variables)
> (add-extra-type (make-regexp typedefs))
>
> ;; Reset font-lock
> (font-lock-mode 0)
> (font-lock-mode 1))))
>
> ;; Called to add the types when the hook executes.
> (defun add-extra-type (new_type)
> (setq c-font-lock-extra-types
> (cons new_type c++-font-lock-extra-types))
> (setq c++-font-lock-extra-types c-font-lock-extra-types)
> )
>
> Part of my c-mode-hook:
>
> (if typedefs (add-extra-type (make-regexp typedefs)))
>
> ----------------------------------------------------------------------------------
>
> So what do I need to do to make this typedef variable always safe? Or
> where do I look in the docs to learn how to do this?
>
> Thanks again for your help!
>
> -Eric Twietmeyer
Well, looking through files.el where all of this stuff is used, it
looks like perhaps this is what I needed to do:
(defvar typedefs nil "Typedefs in this buffer.")
(make-variable-buffer-local 'typedefs)
(put 'typedefs 'safe-local-variable '(lambda (x) t))
It looked like the safe-local-variable property is what controls
things.
Please let me know if this is the correct way, thanks!
-Eric Twietmeyer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-02 2:21 ` enable-local-variables Eric Twietmeyer
@ 2007-01-02 6:56 ` Ralf Angeli
2007-01-02 14:55 ` enable-local-variables Eric Twietmeyer
0 siblings, 1 reply; 10+ messages in thread
From: Ralf Angeli @ 2007-01-02 6:56 UTC (permalink / raw)
* Eric Twietmeyer (2007-01-02) writes:
> Eric Twietmeyer wrote:
>> Ralf Angeli wrote:
>> >
>> > Then
>> > (put 'typedefs 'safe-local-variable 'listp)
>> > should work.
[...]
>> Ok, now I understand the confusion. I didn't realize that my extended
>> .emacs had code I took long ago from someone that added this "feature",
>> I thought it was part of the standard font-lock stuff. Here is the
>> relevant code:
You could propose something like that as a feature request to CC mode
maintainers.
>> So what do I need to do to make this typedef variable always safe? Or
>> where do I look in the docs to learn how to do this?
See above.
> Well, looking through files.el where all of this stuff is used, it
> looks like perhaps this is what I needed to do:
>
> (defvar typedefs nil "Typedefs in this buffer.")
> (make-variable-buffer-local 'typedefs)
> (put 'typedefs 'safe-local-variable '(lambda (x) t))
>
> It looked like the safe-local-variable property is what controls
> things.
>
> Please let me know if this is the correct way, thanks!
See above.
--
Ralf
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: enable-local-variables
2007-01-02 6:56 ` enable-local-variables Ralf Angeli
@ 2007-01-02 14:55 ` Eric Twietmeyer
0 siblings, 0 replies; 10+ messages in thread
From: Eric Twietmeyer @ 2007-01-02 14:55 UTC (permalink / raw)
Ralf Angeli wrote:
> * Eric Twietmeyer (2007-01-02) writes:
>
> > Eric Twietmeyer wrote:
> >> Ralf Angeli wrote:
> >> >
> >> > Then
> >> > (put 'typedefs 'safe-local-variable 'listp)
> >> > should work.
> [...]
> >> Ok, now I understand the confusion. I didn't realize that my extended
> >> .emacs had code I took long ago from someone that added this "feature",
> >> I thought it was part of the standard font-lock stuff. Here is the
> >> relevant code:
>
> You could propose something like that as a feature request to CC mode
> maintainers.
>
> >> So what do I need to do to make this typedef variable always safe? Or
> >> where do I look in the docs to learn how to do this?
>
> See above.
>
> > Well, looking through files.el where all of this stuff is used, it
> > looks like perhaps this is what I needed to do:
> >
> > (defvar typedefs nil "Typedefs in this buffer.")
> > (make-variable-buffer-local 'typedefs)
> > (put 'typedefs 'safe-local-variable '(lambda (x) t))
> >
> > It looked like the safe-local-variable property is what controls
> > things.
> >
> > Please let me know if this is the correct way, thanks!
>
> See above.
>
> --
> Ralf
Now I understand your original posts. Thanks for your patience and
your help.
-Eric Twietmeyer
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2007-01-02 14:55 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-01 20:04 enable-local-variables Eric Twietmeyer
2007-01-01 20:43 ` enable-local-variables Leo
2007-01-01 21:45 ` enable-local-variables Ralf Angeli
2007-01-01 22:27 ` enable-local-variables Eric Twietmeyer
2007-01-01 22:50 ` enable-local-variables Ralf Angeli
2007-01-02 0:21 ` enable-local-variables Eric Twietmeyer
2007-01-02 2:21 ` enable-local-variables Eric Twietmeyer
2007-01-02 6:56 ` enable-local-variables Ralf Angeli
2007-01-02 14:55 ` enable-local-variables Eric Twietmeyer
[not found] ` <mailman.2620.1167684196.2155.help-gnu-emacs@gnu.org>
2007-01-01 22:21 ` enable-local-variables Eric Twietmeyer
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.