emacs-devel
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el


From: Ted Zlatanov
Subject: Re: [Emacs-diffs] /srv/bzr/emacs/trunk r112104: * progmodes/cfengine.el (cfengine-common-syntax): Add "_" to word syntax.
Date: Fri, 22 Mar 2013 10:46:43 -0400
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3.50 (gnu/linux)

On Fri, 22 Mar 2013 10:18:37 -0400 Stefan Monnier <address@hidden> wrote: 

>> OK, but I can't think of any cases in CFEngine specifically where I
>> don't want to skip over _ with M-f.  It's always part of a word.
>> The language itself is designed that way and has a pretty rigid syntax.

SM> CFengine has no notion of words, it has a notion of identifiers, which
SM> in Emacs are called symbols and can be skipped with C-M-f or
SM> forward-symbol.

>> Or are you saying users don't expect _ to be part of a
>> word and it's unconventional to make it so?

SM> Exactly.  Many users actually like _ to be part of a word, but these are
SM> user-preferences (and we should indeed define a words-are-symbols-mode
SM> for those users since what they really want is for M-f, M-t, M-DEL to
SM> move by symbols rather than by words).

Yes!  In particular, context expressions in CFEngine are things like
"a_b_c.d_e" and it's a pain to skip over them with the usual `M-f' or
CUA keybindings.  It would be nice to be able to set this as a
preference for all modes derived from `prog-mode', IIUC what you mean.

SM> Basically, the definition of a word is something that major modes should
SM> not touch, because it is a notion from human language, and not from the
SM> programming language in use in a particular buffer.

SM> The major mode should define the syntax of symbols (aka
SM> "identifiers") instead.

OK, I think I understand.  You're saying "words" are not part of the
syntax for a programming language, generally, and are more of a
text-mode concept.  Symbols usually are what I want if I'm parsing a
programming language.

I modified cfengine.el to use \_< and \_> for all the regular
expressions; can you take a look at the attached patch and see if it's
closer to the expected behavior?

Thanks
Ted

=== modified file 'lisp/progmodes/cfengine.el'
*** lisp/progmodes/cfengine.el  2013-03-21 16:11:13 +0000
--- lisp/progmodes/cfengine.el  2013-03-22 14:39:32 +0000
***************
*** 30,40 ****
  ;; The CFEngine 3.x support doesn't have Imenu support but patches are
  ;; welcome.
  
  ;; You can set it up so either `cfengine2-mode' (2.x and earlier) or
  ;; `cfengine3-mode' (3.x) will be picked, depending on the buffer
  ;; contents:
  
! ;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine-mode))
  
  ;; OR you can choose to always use a specific version, if you prefer
  ;; it:
--- 30,42 ----
  ;; The CFEngine 3.x support doesn't have Imenu support but patches are
  ;; welcome.
  
+ ;; By default, CFEngine 3.x syntax is used.
+ 
  ;; You can set it up so either `cfengine2-mode' (2.x and earlier) or
  ;; `cfengine3-mode' (3.x) will be picked, depending on the buffer
  ;; contents:
  
! ;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine-auto-mode))
  
  ;; OR you can choose to always use a specific version, if you prefer
  ;; it:
***************
*** 181,187 ****
      ("$(\\([[:alnum:]_]+\\))" 1 font-lock-variable-name-face)
      ("${\\([[:alnum:]_]+\\)}" 1 font-lock-variable-name-face)
      ;; Variable definitions.
!     ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
      ;; File, acl &c in group:   { token ... }
      ("{[ \t]*\\([^ \t\n]+\\)" 1 font-lock-constant-face)))
  
--- 183,189 ----
      ("$(\\([[:alnum:]_]+\\))" 1 font-lock-variable-name-face)
      ("${\\([[:alnum:]_]+\\)}" 1 font-lock-variable-name-face)
      ;; Variable definitions.
!     ("\\_<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
      ;; File, acl &c in group:   { token ... }
      ("{[ \t]*\\([^ \t\n]+\\)" 1 font-lock-constant-face)))
  
***************
*** 189,197 ****
    `(
      ;; Defuns.  This happens early so they don't get caught by looser
      ;; patterns.
!     (,(concat "\\<" cfengine3-defuns-regex "\\>"
!               "[ \t]+\\<\\([[:alnum:]_.:]+\\)\\>"
!               "[ \t]+\\<\\([[:alnum:]_.:]+\\)"
                ;; Optional parentheses with variable names inside.
                "\\(?:(\\([^)]*\\))\\)?")
       (1 font-lock-builtin-face)
--- 191,199 ----
    `(
      ;; Defuns.  This happens early so they don't get caught by looser
      ;; patterns.
!     (,(concat "\\_<" cfengine3-defuns-regex "\\_>"
!               "[ \t]+\\_<\\([[:alnum:]_.:]+\\)\\_>"
!               "[ \t]+\\_<\\([[:alnum:]_.:]+\\)"
                ;; Optional parentheses with variable names inside.
                "\\(?:(\\([^)]*\\))\\)?")
       (1 font-lock-builtin-face)
***************
*** 212,221 ****
      ("address@hidden([[:alnum:]_.:]+\\)}" 1 font-lock-variable-name-face)
  
      ;; Variable definitions.
!     ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
  
      ;; Variable types.
!     (,(concat "\\<" (eval-when-compile (regexp-opt cfengine3-vartypes t)) 
"\\>")
       1 font-lock-type-face)))
  
  (defvar cfengine2-imenu-expression
--- 214,223 ----
      ("address@hidden([[:alnum:]_.:]+\\)}" 1 font-lock-variable-name-face)
  
      ;; Variable definitions.
!     ("\\_<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
  
      ;; Variable types.
!     (,(concat "\\_<" (eval-when-compile (regexp-opt cfengine3-vartypes t)) 
"\\_>")
       1 font-lock-type-face)))
  
  (defvar cfengine2-imenu-expression
***************
*** 223,231 ****
                              (regexp-opt cfengine2-actions t))
                  ":[^:]")
         1)
!     ("Variables/classes" "\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1)
!     ("Variables/classes" "\\<define=\\([[:alnum:]_]+\\)" 1)
!     ("Variables/classes" "\\<DefineClass\\>[ \t]+\\([[:alnum:]_]+\\)" 1))
    "`imenu-generic-expression' for CFEngine mode.")
  
  (defun cfengine2-outline-level ()
--- 225,233 ----
                              (regexp-opt cfengine2-actions t))
                  ":[^:]")
         1)
!     ("Variables/classes" "\\_<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1)
!     ("Variables/classes" "\\_<define=\\([[:alnum:]_]+\\)" 1)
!     ("Variables/classes" "\\_<DefineClass\\>[ \t]+\\([[:alnum:]_]+\\)" 1))
    "`imenu-generic-expression' for CFEngine mode.")
  
  (defun cfengine2-outline-level ()
***************
*** 338,344 ****
  Treats body/bundle blocks as defuns."
    (unless (<= (current-column) (current-indentation))
      (end-of-line))
!   (if (re-search-backward (concat "^[ \t]*" cfengine3-defuns-regex "\\>") nil 
t)
        (beginning-of-line)
      (goto-char (point-min)))
    t)
--- 340,346 ----
  Treats body/bundle blocks as defuns."
    (unless (<= (current-column) (current-indentation))
      (end-of-line))
!   (if (re-search-backward (concat "^[ \t]*" cfengine3-defuns-regex "\\_>") 
nil t)
        (beginning-of-line)
      (goto-char (point-min)))
    t)
***************
*** 347,353 ****
    "`end-of-defun' function for Cfengine 3 mode.
  Treats body/bundle blocks as defuns."
    (end-of-line)
!   (if (re-search-forward (concat "^[ \t]*" cfengine3-defuns-regex "\\>") nil 
t)
        (beginning-of-line)
      (goto-char (point-max)))
    t)
--- 349,355 ----
    "`end-of-defun' function for Cfengine 3 mode.
  Treats body/bundle blocks as defuns."
    (end-of-line)
!   (if (re-search-forward (concat "^[ \t]*" cfengine3-defuns-regex "\\_>") nil 
t)
        (beginning-of-line)
      (goto-char (point-max)))
    t)
***************
*** 366,372 ****
  
        (cond
         ;; Body/bundle blocks start at 0.
!        ((looking-at (concat cfengine3-defuns-regex "\\>"))
          (indent-line-to 0))
         ;; Categories are indented one step.
         ((looking-at (concat cfengine3-category-regex "[ \t]*\\(#.*\\)*$"))
--- 368,374 ----
  
        (cond
         ;; Body/bundle blocks start at 0.
!        ((looking-at (concat cfengine3-defuns-regex "\\_>"))
          (indent-line-to 0))
         ;; Categories are indented one step.
         ((looking-at (concat cfengine3-category-regex "[ \t]*\\(#.*\\)*$"))
***************
*** 516,522 ****
  
  (defun cfengine-common-syntax (table)
    ;; The syntax defaults seem OK to give reasonable word movement.
-   (modify-syntax-entry ?w "_" table)
    (modify-syntax-entry ?# "<" table)
    (modify-syntax-entry ?\n ">#" table)
    (modify-syntax-entry ?\" "\"" table)  ; "string"
--- 518,523 ----
***************
*** 584,590 ****
      (save-restriction
        (goto-char (point-min))
        (while (not (or (eobp) v3))
!         (setq v3 (looking-at (concat cfengine3-defuns-regex "\\>")))
          (forward-line)))
      (if v3 (cfengine3-mode) (cfengine2-mode))))
  
--- 585,591 ----
      (save-restriction
        (goto-char (point-min))
        (while (not (or (eobp) v3))
!         (setq v3 (looking-at (concat cfengine3-defuns-regex "\\_>")))
          (forward-line)))
      (if v3 (cfengine3-mode) (cfengine2-mode))))
  


reply via email to

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