From: Yagnesh Raghava Yakkala <hi@yagnesh.org>
To: Josh <josh@foxtail.org>
Cc: emacs-devel@gnu.org
Subject: Re: help with smie
Date: Fri, 22 Feb 2013 05:41:21 +0900 [thread overview]
Message-ID: <87vc9l9z7y.fsf@yagnesh.org> (raw)
In-Reply-To: <CANdFEAETBfDreZxSX3WUa4mxRxSozx3U5cQhoju00kXtJX30Qg@mail.gmail.com> (josh@foxtail.org's message of "Thu, 21 Feb 2013 12:32:54 -0800")
Hello ,
Thanks for the reply,
On Feb 22 2013, Josh <josh@foxtail.org> wrote:
> On Thu, Feb 21, 2013 at 11:40 AM, Yagnesh Raghava Yakkala
> <hi@yagnesh.org> wrote:
>> So I decided to first try SMIE work for another small major mode called
>> namelist-mode². Namelist files are sort of configuration files Fortran
>> programs (you may already know that).
>> [...]
>> I wrote smie rules in the mode, tried to see how it works. No surprise they
>> didn't work.
>
> I tried a similar exercise recently, with similar results. I read in
> (info "(elisp) SMIE setup")
> that SMIE's "main entry point is `smie-setup' which is a function
> typically called while setting
> up a major mode." Would it make sense to add an example of a simple
> SMIE-based major
> mode to (info "(elisp) Example Major Modes") ?
Yes, I read that, and I have set smie-setup in my code. may I should have
pasted the code here.
Part of the smie related code:
--8<---------------cut here---------------start------------->8---
(require 'smie)
(defconst namelist-use-smie nil
"Whether to use SMIE for indentation.")
(defvar namelist-keywords-regexp
(regexp-opt '("," "/"))
"For SMIE.")
(defconst namelist-smie-tokens
'(("BEGIN" . "&")
("END" . '("/" "$END"))
("OP" . "=")))
(defvar namelist-smie-grammer
(smie-prec2->grammar
(smie-bnf->prec2
'((id)
(inst ("BEGIN" exp "END")
(exp))
(exp (id "," id)
(id "=" exp)))
'((assoc ","))))
"SMIE grammar for namelist mode.")
(defun namelist-smie-rules (kind token)
(case kind
(:after
(cond
((equal token ",") (smie-rule-separator kind))
((equal token "BEGIN") namelist-indent-offset)))
(:before
(cond
((equal token ",") (smie-rule-separator kind))
))
(:elem
(cond
((equal "BEGIN") '(column . 0))
((equal "END") '(column . 0))))))
(defun namelist-smie-forward-token ()
(forward-comment (point-max))
(cond
((looking-at namelist-keywords-regexp)
(goto-char (match-end 0))
(match-string-no-properties 0))
(t (buffer-substring-no-properties
(point)
(progn (skip-syntax-forward "w_")
(point))))))
(defun namelist-smie-backward-token ()
(forward-comment (- (point)))
(cond
((looking-back namelist-keywords-regexp (- (point) 2) t)
(goto-char (match-beginning 0))
(match-string-no-properties 0))
(t (buffer-substring-no-properties
(point)
(progn (skip-syntax-backward "w_")
(point))))))
(define-derived-mode namelist-mode prog-mode "namelist"
"Major mode for editing f90 namelist files.
\\{namelist-mode-map}"
;; (set (make-local-variable 'indent-line-function) 'namelist-indent-line)
(set (make-local-variable 'indent-line-function) 'smie-indent-line)
(set (make-local-variable 'comment-start) namelist-comment-char)
(setq indent-tabs-mode nil)
(set (make-local-variable 'imenu-generic-expression)
namelist-imenu-generic-expression)
(set (make-local-variable 'font-lock-defaults)
'(namelist-font-lock-keywords))
(smie-setup namelist-smie-grammer
#'namelist-smie-rules
:forward-token #'namelist-smie-forward-token
:backward-token #'namelist-smie-backward-token))
--8<---------------cut here---------------end--------------->8---
Thanks.,
--
ఎందరో మహానుభావులు అందరికి వందనములు.
YYR
next prev parent reply other threads:[~2013-02-21 20:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-21 19:40 help with smie Yagnesh Raghava Yakkala
2013-02-21 20:32 ` Josh
2013-02-21 20:41 ` Yagnesh Raghava Yakkala [this message]
2013-02-22 18:11 ` Stephen Leake
2013-02-25 4:40 ` Stefan Monnier
2013-02-25 4:38 ` Stefan Monnier
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=87vc9l9z7y.fsf@yagnesh.org \
--to=hi@yagnesh.org \
--cc=emacs-devel@gnu.org \
--cc=josh@foxtail.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.