[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with smie

From: Yagnesh Raghava Yakkala
Subject: Re: help with smie
Date: Fri, 22 Feb 2013 05:41:21 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hello ,

Thanks for the reply,

On Feb 22 2013, Josh <address@hidden> wrote:

> On Thu, Feb 21, 2013 at 11:40 AM, Yagnesh Raghava Yakkala
> <address@hidden> 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
      (inst ("BEGIN" exp "END")
      (exp (id "," id)
           (id "=" exp)))
    '((assoc ","))))
  "SMIE grammar for namelist mode.")

(defun namelist-smie-rules (kind token)
  (case kind
      ((equal token ",") (smie-rule-separator kind))
      ((equal token "BEGIN") namelist-indent-offset)))
      ((equal token ",") (smie-rule-separator kind))
      ((equal "BEGIN") '(column . 0))
      ((equal "END") '(column . 0))))))

(defun namelist-smie-forward-token ()
  (forward-comment (point-max))
   ((looking-at namelist-keywords-regexp)
    (goto-char (match-end 0))
    (match-string-no-properties 0))
   (t (buffer-substring-no-properties
       (progn (skip-syntax-forward "w_")

(defun namelist-smie-backward-token ()
  (forward-comment (- (point)))
   ((looking-back namelist-keywords-regexp (- (point) 2) t)
    (goto-char (match-beginning 0))
    (match-string-no-properties 0))
   (t (buffer-substring-no-properties
       (progn (skip-syntax-backward "w_")

(define-derived-mode namelist-mode prog-mode "namelist"
  "Major mode for editing f90 namelist files.

  ;; (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)
  (set (make-local-variable 'font-lock-defaults)
  (smie-setup namelist-smie-grammer
              :forward-token #'namelist-smie-forward-token
              :backward-token #'namelist-smie-backward-token))
--8<---------------cut here---------------end--------------->8---

ఎందరో మహానుభావులు అందరికి వందనములు.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]