all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Stefan Monnier" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu>
Subject: Re: Font-lock with newcomment.el
Date: 30 May 2003 12:34:41 -0400	[thread overview]
Message-ID: <5lvfvsmlzy.fsf@rum.cs.yale.edu> (raw)
In-Reply-To: eyuadd4ea0z.fsf@canonmills.inf.ed.ac.uk

>   (setq font-lock-defaults '((nrnhoc-font-lock-keywords)
>                              nil ; do not do string/comment highlighting
>                              nil ; keywords are case sensitive.
>                              nil
>                              ))
>   (modify-syntax-entry ?_  "w")
>   (modify-syntax-entry ?\n  "> b")
>   (modify-syntax-entry ?/  (
>                             if (string-match "XEmacs" (emacs-version))
>                                ". 1456"
>                              ". 124b"))
>   (modify-syntax-entry ?*  ". 23")
>   (modify-syntax-entry ?\^m  "> b")

Look at the SampleMode code in the www.emacswiki.org.  It shows the
canonical way to setup a mode's syntax-table.  It's generally better
to leave this stuff outside of the major-mode function itself.

>> Oh, and David, regarding your mode: do a C-h f looking-at, that
>> will save you a bunch of buffer-substrings.

> Thanks for looking at the code.  From the looking-at documentation,
> it seems like it only matches regexps after the point, whereas in the
> current way of doing indentation I need to match symbols anywhere in
> the line, in most cases at least.  So it's not clear to me how
> looking-at will help, unless I rethink the indentation code.  

Then use re-search-forward (with a (line-end-position) limit if necessary).
Also, rather than using regexp-matching to find { and } and comment-markers,
it's a lot more robust to use sexp-based operations, such as
(forward-sexp -1) and/or (up-list -1).  If you (buffer-locally) set
parse-sexp-ignore-comments (which you should) they will automatically skip
comments (i.e. they will properly handle the case where you have a { inside
a comment).  Indentation in Emacs is still a black art, sadly, but
most of the indentation functions I've written have at their core a loop
that looks like

    (let ((outside-pos nil)
          (start pos (point)))
      (condition-case err
           (while
               (progn
                 (forward-sexp -1)
                 ;; Are we at the beginning of the line?
                 (save-excursion (skip-chars-backward " \t") (not (bolp)))))
         (scan-error
          (setq outside-pos (nth 2 err))))
      ;; Now we're either at the beginning of a previous line at the same
      ;; parenthesis level (in which case `outside-pos' is nil) or we're
      ;; looking at the first element after the open paren in which the
      ;; line we're coming from is enclosed (in which case `outside-pos'
      ;; is the position of that paren).
      (if (or (null outside-pos) (< (point) start))
          ;; We're at the start of a previous line at the same paren level.
          (current-indentation)
        ;; We're the first thing after the open paren:
        ;; indent relative to open-paren.
        (goto-char outside-pos)
        (+ basic-indent (current-indentation))))


        Stefan

PS: You might also like to use `regexp-opt' to build the regexps matching
a list of keywords.  Makes the code more readable.

  parent reply	other threads:[~2003-05-30 16:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-29 16:07 Font-lock with newcomment.el David C Sterratt
2003-05-29 17:22 ` lawrence mitchell
2003-05-29 17:31 ` Stefan Monnier
2003-05-30 11:12   ` David C Sterratt
2003-05-30 11:45     ` lawrence mitchell
2003-05-30 13:57       ` Stefan Monnier
2003-05-30 15:20         ` David C Sterratt
2003-05-30 16:23           ` Kevin Rodgers
2003-06-02 10:06             ` David C Sterratt
2003-05-30 16:34           ` Stefan Monnier [this message]
2003-05-30 15:02       ` David C Sterratt

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=5lvfvsmlzy.fsf@rum.cs.yale.edu \
    --to=monnier+gnu.emacs.help/news/@flint.cs.yale.edu \
    /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.