unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Eric Twietmeyer" <zimbus26@yahoo.com>
Subject: Re: enable-local-variables
Date: 1 Jan 2007 16:21:56 -0800	[thread overview]
Message-ID: <1167697316.065889.189060@i12g2000cwa.googlegroups.com> (raw)
In-Reply-To: 45999042$0$30319$9b4e6d93@newsspool1.arcor-online.net

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

  reply	other threads:[~2007-01-02  0:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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       ` Eric Twietmeyer [this message]
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

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1167697316.065889.189060@i12g2000cwa.googlegroups.com \
    --to=zimbus26@yahoo.com \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).