Enhanced cperl-mode.el (Perl editing mode for Emacs) 
Author Message
 Enhanced cperl-mode.el (Perl editing mode for Emacs)

I was contacted to incorporate my changes to cperl-mode.el into the
file distributed with the perl sources. I did it, so please try the
following file and send comments to me ASAP.

Take care,
Ilya


;;; Newsgroups: comp.lang.perl
;;; Subject: cperl-mode: Another perl mode for Gnuemacs
;;; Date: 14 Aug 91 15:20:01 GMT

;; Perl code editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.

;; This file is not (yet) part of GNU Emacs.


;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

;;; To use this mode put the following into your .emacs file:

;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)

;;; Additional useful commands to put into your .emacs file:

;; (setq auto-mode-alist
;;       (append '(("\\.[pP][Llm]$" . perl-mode))  auto-mode-alist ))
;; (setq interpreter-mode-alist (append interpreter-mode-alist
;;                                      '(("miniperl" . perl-mode))))

;;; The mode information (on C-h m) provides customization help.
;;; If you use font-lock feature of this mode, it is advisable to use
;;; eather lazy-lock-mode or fast-lock-mode (available on ELisp
;;; archive in files lazy-lock.el and fast-lock.el). I prefer lazy-lock.

;;; Probably it is too late to set these guys already, but it can help later:

(setq auto-mode-alist
      (append '(("\\.[pP][Llm]$" . perl-mode))  auto-mode-alist ))
(setq interpreter-mode-alist (append interpreter-mode-alist
                                     '(("miniperl" . perl-mode))))

(defvar cperl-mode-abbrev-table nil
  "Abbrev table in use in Cperl-mode buffers.")
(define-abbrev-table 'cperl-mode-abbrev-table ())

(defvar cperl-mode-map ()
  "Keymap used in C mode.")
(if cperl-mode-map
    ()
  (setq cperl-mode-map (make-sparse-keymap))
  (define-key cperl-mode-map "{" 'electric-cperl-brace)
  (define-key cperl-mode-map "}" 'electric-cperl-brace)
  (define-key cperl-mode-map ";" 'electric-cperl-semi)
  (define-key cperl-mode-map ":" 'electric-cperl-terminator)
  (define-key cperl-mode-map "\e\C-h" 'mark-cperl-function)
  (define-key cperl-mode-map "\e\C-q" 'indent-cperl-exp)
  (define-key cperl-mode-map "\177" 'backward-delete-char-untabify)
  (define-key cperl-mode-map "\t" 'cperl-indent-command))

(autoload 'cperl-macro-expand "cmacexp"
  "Display the result of expanding all C macros occurring in the region.
The expansion is entirely correct because it uses the C preprocessor."
  t)

(defvar cperl-mode-syntax-table nil
  "Syntax table in use in Cperl-mode buffers.")

(if cperl-mode-syntax-table
    ()
  (setq cperl-mode-syntax-table (make-syntax-table))
  (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
  (modify-syntax-entry ?/ ". 14" cperl-mode-syntax-table)
  (modify-syntax-entry ?* ". 23" cperl-mode-syntax-table)
  (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
  (modify-syntax-entry ?- "." cperl-mode-syntax-table)
  (modify-syntax-entry ?= "." cperl-mode-syntax-table)
  (modify-syntax-entry ?% "." cperl-mode-syntax-table)
  (modify-syntax-entry ?< "." cperl-mode-syntax-table)
  (modify-syntax-entry ?> "." cperl-mode-syntax-table)
  (modify-syntax-entry ?& "." cperl-mode-syntax-table)
  (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
  (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
  (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
  (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
  (modify-syntax-entry ?_ "w" cperl-mode-syntax-table)
  (modify-syntax-entry ?| "." cperl-mode-syntax-table))

(defvar cperl-indent-level 2
  "*Indentation of C statements with respect to containing block.")
(defvar cperl-brace-imaginary-offset 0
  "*Imagined indentation of a C open brace that actually follows a statement.")
(defvar cperl-brace-offset 0
  "*Extra indentation for braces, compared with other text in same context.")
(defvar cperl-argdecl-indent 5
  "*Indentation level of declarations of C function arguments.")
(defvar cperl-label-offset -2
  "*Offset of C label lines and case statements relative to usual indentation.")
(defvar cperl-continued-statement-offset 2
  "*Extra indent for lines not starting new statements.")
(defvar cperl-continued-brace-offset 0
  "*Extra indent for substatements that start with open-braces.
This is in addition to cperl-continued-statement-offset.")

(defvar cperl-auto-newline nil
  "*Non-nil means automatically newline before and after braces,
and after colons and semicolons, inserted in C code.")

(defvar cperl-tab-always-indent t
  "*Non-nil means TAB in C mode should always reindent the current line,
regardless of where in the line point is when the TAB command is used.")

(defvar cperl-font-lock t
  "*Non-nil means CPerl buffers will use font-lock-mode.")

;; provide an alias for working with emacs 19.  the perl-mode that comes
;; with it is really bad, and this lets us seamlessly replace it.
(fset 'perl-mode 'cperl-mode)
(defun cperl-mode ()
  "Major mode for editing Perl code.
Expression and list commands understand all C brackets.
Tab indents for Perl code.
Paragraphs are separated by blank lines only.
Delete converts tabs to spaces as it moves back.
\\{cperl-mode-map}
Setting the variable `cperl-font-lock' to nil switches off font-lock-mode.
Variables controlling indentation style:
 `cperl-tab-always-indent'
    Non-nil means TAB in C mode should always reindent the current line,
    regardless of where in the line point is when the TAB command is used.
 `cperl-auto-newline'
    Non-nil means automatically newline before and after braces,
    and after colons and semicolons, inserted in C code.
 `cperl-indent-level'
    Indentation of C statements within surrounding block.
    The surrounding block's indentation is the indentation
    of the line on which the open-brace appears.
 `cperl-continued-statement-offset'
    Extra indentation given to a substatement, such as the
    then-clause of an if or body of a while.
 `cperl-continued-brace-offset'
    Extra indentation given to a brace that starts a substatement.
    This is in addition to cperl-continued-statement-offset.
 `cperl-brace-offset'
    Extra indentation for line if it starts with an open brace.
 `cperl-brace-imaginary-offset'
    An open brace following other text is treated as if it were
    this far to the right of the start of its line.
 `cperl-argdecl-indent'
    Indentation level of declarations of C function arguments.
 `cperl-label-offset'
    Extra indentation for line that is a label, or case or default.

Settings for K&R and BSD indentation styles are
  `cperl-indent-level'                5    8
  `cperl-continued-statement-offset'  5    8
  `cperl-brace-offset'               -5   -8
  `cperl-argdecl-indent'              0    8
  `cperl-label-offset'               -5   -8

Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
with no args."
  (interactive)
  (kill-all-local-variables)
  (use-local-map cperl-mode-map)
  (setq major-mode 'perl-mode)
  (setq mode-name "CPerl")
  (setq local-abbrev-table cperl-mode-abbrev-table)
  (set-syntax-table cperl-mode-syntax-table)
  (make-local-variable 'paragraph-start)
  (setq paragraph-start (concat "^$\\|" page-delimiter))
  (make-local-variable 'paragraph-separate)
  (setq paragraph-separate paragraph-start)
  (make-local-variable 'paragraph-ignore-fill-prefix)
  (setq paragraph-ignore-fill-prefix t)
  (make-local-variable 'indent-line-function)
  (setq indent-line-function 'cperl-indent-line)
  (make-local-variable 'require-final-newline)
  (setq require-final-newline t)
  (make-local-variable 'comment-start)
  (setq comment-start "# ")
  (make-local-variable 'comment-end)
  (setq comment-end "")
  (make-local-variable 'comment-column)
  (setq comment-column 32)
  (make-local-variable 'comment-start-skip)
  (setq comment-start-skip "# *")
  (make-local-variable 'comment-indent-hook)
  (setq comment-indent-hook 'cperl-comment-indent)
  (make-local-variable 'parse-sexp-ignore-comments)
  (setq parse-sexp-ignore-comments t)
  (make-local-variable 'imenu-create-index-function)
  (setq imenu-create-index-function
        (function imenu-example--create-perl-index))
  (if window-system
      (if cperl-font-lock (font-lock-mode 1)))
  (run-hooks 'cperl-mode-hook))

;; This is used by indent-for-comment
;; to decide how much to indent a comment in C code
;; based on its context.
(defun cperl-comment-indent ()
  (if (looking-at "^#")
      0                         ;Existing comment at bol stays there.
    (save-excursion
      (skip-chars-backward " \t")
      (max (1+ (current-column))        ;Else indent at comment column
           comment-column))))   ; except leave at least one space.

(defun electric-cperl-brace (arg)
  "Insert character and correct line's indentation."
  (interactive "P")
  (let (insertpos)
    (if (and (not arg)
             (eolp)
             (or (save-excursion
                   (skip-chars-backward " \t")
                   (bolp))
                 (if cperl-auto-newline (progn (cperl-indent-line) (newline) t) nil)))
        (progn
          (insert last-command-char)
          (cperl-indent-line)
          (if cperl-auto-newline
              (progn
                (newline)
                ;; (newline) may have done auto-fill
                (setq insertpos (- (point) 2))
                (cperl-indent-line)))
          (save-excursion
            (if insertpos
...

read more »



Sun, 04 May 1997 09:22:30 GMT  
 Enhanced cperl-mode.el (Perl editing mode for Emacs)

Quote:

> I was contacted to incorporate my changes to cperl-mode.el into the
> file distributed with the perl sources. I did it, so please try the
> following file and send comments to me ASAP.

> Take care,
> Ilya

Here is the second pass. It improves font handling if you use a font
without bold and italic variants, and IT CAN INDENT CORRECT (sometimes
:-). The improvements to indention code concern comment handling and
handling of embedded ::.
        However, a new BIG problem is discovered: the main trick (to
make $ a "backslash") makes constructions like ${aaa} look like
unbalanced braces. The only  trick I can think out is to insert it as
$ {aaa} (legal in perl). If somebody can hack the code that installes
{ to make this automatically, I will gladly merge it into the sources.

Your constructive criticism is welcome.

This is still a bastard of C mode...


;;; Newsgroups: comp.lang.perl
;;; Subject: cperl-mode: Another perl mode for Gnuemacs
;;; Date: 14 Aug 91 15:20:01 GMT

;; Perl code editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.

;; This file is not (yet) part of GNU Emacs.


;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

;;; To use this mode put the following into your .emacs file:

;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)

;;; Additional useful commands to put into your .emacs file:

;; (setq auto-mode-alist
;;       (append '(("\\.[pP][Llm]$" . perl-mode))  auto-mode-alist ))
;; (setq interpreter-mode-alist (append interpreter-mode-alist
;;                                      '(("miniperl" . perl-mode))))

;;; The mode information (on C-h m) provides customization help.
;;; If you use font-lock feature of this mode, it is advisable to use
;;; eather lazy-lock-mode or fast-lock-mode (available on ELisp
;;; archive in files lazy-lock.el and fast-lock.el). I prefer lazy-lock.

;;; Probably it is too late to set these guys already, but it can help later:

(setq auto-mode-alist
      (append '(("\\.[pP][Llm]$" . perl-mode))  auto-mode-alist ))
(setq interpreter-mode-alist (append interpreter-mode-alist
                                     '(("miniperl" . perl-mode))))

(defvar cperl-mode-abbrev-table nil
  "Abbrev table in use in Cperl-mode buffers.")
(define-abbrev-table 'cperl-mode-abbrev-table ())

(defvar cperl-mode-map ()
  "Keymap used in C mode.")
(if cperl-mode-map
    ()
  (setq cperl-mode-map (make-sparse-keymap))
  (define-key cperl-mode-map "{" 'electric-cperl-brace)
  (define-key cperl-mode-map "}" 'electric-cperl-brace)
  (define-key cperl-mode-map ";" 'electric-cperl-semi)
  (define-key cperl-mode-map ":" 'electric-cperl-terminator)
  (define-key cperl-mode-map "\e\C-h" 'mark-cperl-function)
  (define-key cperl-mode-map "\e\C-q" 'indent-cperl-exp)
  (define-key cperl-mode-map "\177" 'backward-delete-char-untabify)
  (define-key cperl-mode-map "\t" 'cperl-indent-command))

(autoload 'cperl-macro-expand "cmacexp"
  "Display the result of expanding all C macros occurring in the region.
The expansion is entirely correct because it uses the C preprocessor."
  t)

(defvar cperl-mode-syntax-table nil
  "Syntax table in use in Cperl-mode buffers.")

(if cperl-mode-syntax-table
    ()
  (setq cperl-mode-syntax-table (make-syntax-table))
  (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
  (modify-syntax-entry ?/ ". 14" cperl-mode-syntax-table)
  (modify-syntax-entry ?* ". 23" cperl-mode-syntax-table)
  (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
  (modify-syntax-entry ?- "." cperl-mode-syntax-table)
  (modify-syntax-entry ?= "." cperl-mode-syntax-table)
  (modify-syntax-entry ?% "." cperl-mode-syntax-table)
  (modify-syntax-entry ?< "." cperl-mode-syntax-table)
  (modify-syntax-entry ?> "." cperl-mode-syntax-table)
  (modify-syntax-entry ?& "." cperl-mode-syntax-table)
  (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
  (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
  (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
  (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
  (modify-syntax-entry ?_ "w" cperl-mode-syntax-table)
  (modify-syntax-entry ?| "." cperl-mode-syntax-table))

(defvar cperl-indent-level 2
  "*Indentation of C statements with respect to containing block.")
(defvar cperl-brace-imaginary-offset 0
  "*Imagined indentation of a C open brace that actually follows a statement.")
(defvar cperl-brace-offset 0
  "*Extra indentation for braces, compared with other text in same context.")
(defvar cperl-argdecl-indent 5
  "*Indentation level of declarations of C function arguments.")
(defvar cperl-label-offset -2
  "*Offset of C label lines and case statements relative to usual indentation.")
(defvar cperl-continued-statement-offset 2
  "*Extra indent for lines not starting new statements.")
(defvar cperl-continued-brace-offset 0
  "*Extra indent for substatements that start with open-braces.
This is in addition to cperl-continued-statement-offset.")

(defvar cperl-auto-newline nil
  "*Non-nil means automatically newline before and after braces,
and after colons and semicolons, inserted in C code.")

(defvar cperl-tab-always-indent t
  "*Non-nil means TAB in C mode should always reindent the current line,
regardless of where in the line point is when the TAB command is used.")

(defvar cperl-font-lock t
  "*Non-nil means CPerl buffers will use font-lock-mode.")

;; provide an alias for working with emacs 19.  the perl-mode that comes
;; with it is really bad, and this lets us seamlessly replace it.
(fset 'perl-mode 'cperl-mode)
(defun cperl-mode ()
  "Major mode for editing Perl code.
Expression and list commands understand all C brackets.
Tab indents for Perl code.
Paragraphs are separated by blank lines only.
Delete converts tabs to spaces as it moves back.
\\{cperl-mode-map}
Setting the variable `cperl-font-lock' to nil switches off font-lock-mode.
Variables controlling indentation style:
 `cperl-tab-always-indent'
    Non-nil means TAB in CPerl mode should always reindent the current line,
    regardless of where in the line point is when the TAB command is used.
 `cperl-auto-newline'
    Non-nil means automatically newline before and after braces,
    and after colons and semicolons, inserted in Perl code.
 `cperl-indent-level'
    Indentation of C statements within surrounding block.
    The surrounding block's indentation is the indentation
    of the line on which the open-brace appears.
 `cperl-continued-statement-offset'
    Extra indentation given to a substatement, such as the
    then-clause of an if or body of a while.
 `cperl-continued-brace-offset'
    Extra indentation given to a brace that starts a substatement.
    This is in addition to cperl-continued-statement-offset.
 `cperl-brace-offset'
    Extra indentation for line if it starts with an open brace.
 `cperl-brace-imaginary-offset'
    An open brace following other text is treated as if it were
    this far to the right of the start of its line.
 `cperl-argdecl-indent'
    Indentation level of declarations of C function arguments.
 `cperl-label-offset'
    Extra indentation for line that is a label, or case or default.

Settings for K&R and BSD indentation styles are
  `cperl-indent-level'                5    8
  `cperl-continued-statement-offset'  5    8
  `cperl-brace-offset'               -5   -8
  `cperl-argdecl-indent'              0    8
  `cperl-label-offset'               -5   -8

Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook'
with no args."
  (interactive)
  (kill-all-local-variables)
  (use-local-map cperl-mode-map)
  (setq major-mode 'perl-mode)
  (setq mode-name "CPerl")
  (setq local-abbrev-table cperl-mode-abbrev-table)
  (set-syntax-table cperl-mode-syntax-table)
  (make-local-variable 'paragraph-start)
  (setq paragraph-start (concat "^$\\|" page-delimiter))
  (make-local-variable 'paragraph-separate)
  (setq paragraph-separate paragraph-start)
  (make-local-variable 'paragraph-ignore-fill-prefix)
  (setq paragraph-ignore-fill-prefix t)
  (make-local-variable 'indent-line-function)
  (setq indent-line-function 'cperl-indent-line)
  (make-local-variable 'require-final-newline)
  (setq require-final-newline t)
  (make-local-variable 'comment-start)
  (setq comment-start "# ")
  (make-local-variable 'comment-end)
  (setq comment-end "")
  (make-local-variable 'comment-column)
  (setq comment-column 32)
  (make-local-variable 'comment-start-skip)
  (setq comment-start-skip "# *")
  (make-local-variable 'defun-prompt-regexp)
  (setq defun-prompt-regexp "[ \t]*sub[ \t]+\\([^ \t\n{;]+\\)[ \t]*")
  (make-local-variable 'comment-indent-hook)
  (setq comment-indent-hook 'cperl-comment-indent)
  (make-local-variable 'parse-sexp-ignore-comments)
  (setq parse-sexp-ignore-comments t)
  (make-local-variable 'imenu-create-index-function)
  (setq imenu-create-index-function
        (function imenu-example--create-perl-index))
  (if window-system
      (if cperl-font-lock (font-lock-mode 1)))
  (run-hooks 'cperl-mode-hook))

;; This is used by indent-for-comment
;; to decide how much to ...

read more »



Mon, 05 May 1997 09:54:40 GMT  
 Enhanced cperl-mode.el (Perl editing mode for Emacs)

Quote:



> > I was contacted to incorporate my changes to cperl-mode.el into the
> > file distributed with the perl sources. I did it, so please try the
> > following file and send comments to me ASAP.

> > Take care,
> > Ilya

> Here is the second pass. It improves font handling if you use a font
> without bold and italic variants, and IT CAN INDENT CORRECT (sometimes
> :-). The improvements to indention code concern comment handling and
> handling of embedded ::.
>    However, a new BIG problem is discovered: the main trick (to
> make $ a "backslash") makes constructions like ${aaa} look like
> unbalanced braces. The only  trick I can think out is to insert it as
> $ {aaa} (legal in perl). If somebody can hack the code that installes
> { to make this automatically, I will gladly merge it into the sources.

Here is the third pass. It should correct additional problems with
fonts on NeXT, and now has electric features and (sound of drums)
electric linefeed. It knows how to split inline blocks into
multiline.

Enjoy.

Ilya


;;; Newsgroups: comp.lang.perl
;;; Subject: cperl-mode: Another perl mode for Gnuemacs
;;; Date: 14 Aug 91 15:20:01 GMT

;; Perl code editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.

;; This file is not (yet) part of GNU Emacs.


;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

;;; To use this mode put the following into your .emacs file:

;; (autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t)

;;; Additional useful commands to put into your .emacs file:

;; (setq auto-mode-alist
;;       (append '(("\\.[pP][Llm]$" . perl-mode))  auto-mode-alist ))
;; (setq interpreter-mode-alist (append interpreter-mode-alist
;;                                      '(("miniperl" . perl-mode))))

;;; The mode information (on C-h m) provides customization help.
;;; If you use font-lock feature of this mode, it is advisable to use
;;; eather lazy-lock-mode or fast-lock-mode (available on ELisp
;;; archive in files lazy-lock.el and fast-lock.el). I prefer lazy-lock.

;;;; Known problems:

;;; The very new pod
;;; features. The rules are:

;;; /\n=/ should start comment mode, and
;;; /\n=cut\s/ should stop comment mode

;;; The main trick (to
;;; make $ a "backslash") makes constructions like ${aaa} look like
;;; unbalanced braces. The only  trick I can think out is to insert it as
;;; $ {aaa} (legal in perl).

;;; Probably it is too late to set these guys already, but it can help later:

(setq auto-mode-alist
      (append '(("\\.[pP][Llm]$" . perl-mode))  auto-mode-alist ))
(setq interpreter-mode-alist (append interpreter-mode-alist
                                     '(("miniperl" . perl-mode))))

(eval-when-compile
  (require 'imenu)
  (and window-system (require 'font-lock))
  (require 'cl)
  )

(defvar cperl-mode-abbrev-table nil
  "Abbrev table in use in Cperl-mode buffers.")

(defvar cperl-mode-map () "Keymap used in C mode.")

(if cperl-mode-map nil
  (setq cperl-mode-map (make-sparse-keymap))
  (define-key cperl-mode-map "{" 'electric-cperl-lbrace)
  (define-key cperl-mode-map "[" 'electric-cperl-paren)
  (define-key cperl-mode-map "(" 'electric-cperl-paren)
  (define-key cperl-mode-map "<" 'electric-cperl-paren)
  (define-key cperl-mode-map "}" 'electric-cperl-brace)
  (define-key cperl-mode-map ";" 'electric-cperl-semi)
  (define-key cperl-mode-map ":" 'electric-cperl-terminator)
  (define-key cperl-mode-map "\C-j" 'cperl-linefeed)
  (define-key cperl-mode-map "\e\C-h" 'mark-cperl-function)
  (define-key cperl-mode-map "\e\C-q" 'indent-cperl-exp)
  (define-key cperl-mode-map "\177" 'backward-delete-char-untabify)
  (define-key cperl-mode-map "\t" 'cperl-indent-command))

(autoload 'cperl-macro-expand "cmacexp"
  "Display the result of expanding all C macros occurring in the region.
The expansion is entirely correct because it uses the C preprocessor."
  t)

(defvar cperl-mode-syntax-table nil
  "Syntax table in use in Cperl-mode buffers.")

(if cperl-mode-syntax-table
    ()
  (setq cperl-mode-syntax-table (make-syntax-table))
  (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table)
  (modify-syntax-entry ?/ ". 14" cperl-mode-syntax-table)
  (modify-syntax-entry ?* ". 23" cperl-mode-syntax-table)
  (modify-syntax-entry ?+ "." cperl-mode-syntax-table)
  (modify-syntax-entry ?- "." cperl-mode-syntax-table)
  (modify-syntax-entry ?= "." cperl-mode-syntax-table)
  (modify-syntax-entry ?% "." cperl-mode-syntax-table)
  (modify-syntax-entry ?< "." cperl-mode-syntax-table)
  (modify-syntax-entry ?> "." cperl-mode-syntax-table)
  (modify-syntax-entry ?& "." cperl-mode-syntax-table)
  (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table)
  (modify-syntax-entry ?\n ">" cperl-mode-syntax-table)
  (modify-syntax-entry ?# "<" cperl-mode-syntax-table)
  (modify-syntax-entry ?' "\"" cperl-mode-syntax-table)
  (modify-syntax-entry ?_ "w" cperl-mode-syntax-table)
  (modify-syntax-entry ?| "." cperl-mode-syntax-table))

(defvar cperl-indent-level 2
  "*Indentation of C statements with respect to containing block.")
(defvar cperl-brace-imaginary-offset 0
  "*Imagined indentation of a C open brace that actually follows a statement.")
(defvar cperl-brace-offset 0
  "*Extra indentation for braces, compared with other text in same context.")
(defvar cperl-argdecl-indent 5
  "*Indentation level of declarations of C function arguments.")
(defvar cperl-label-offset -2
  "*Offset of C label lines and case statements relative to usual indentation.")
(defvar cperl-continued-statement-offset 2
  "*Extra indent for lines not starting new statements.")
(defvar cperl-continued-brace-offset 0
  "*Extra indent for substatements that start with open-braces.
This is in addition to cperl-continued-statement-offset.")

(defvar cperl-auto-newline nil
  "*Non-nil means automatically newline before and after braces,
and after colons and semicolons, inserted in C code.")

(defvar cperl-tab-always-indent t
  "*Non-nil means TAB in C mode should always reindent the current line,
regardless of where in the line point is when the TAB command is used.")

(defvar cperl-font-lock t
  "*Non-nil means CPerl buffers will use font-lock-mode.")

(defvar electric-cperl-lbrace-space t
  "*Non-nil means { after $ in CPerl buffers should be separated by ` '.")

(defvar electric-cperl-parens "{[(<"
  "*List of parentheses that should be electric in CPerl.")

;; provide an alias for working with emacs 19.  the perl-mode that comes
;; with it is really bad, and this lets us seamlessly replace it.
(fset 'perl-mode 'cperl-mode)
(defun cperl-mode ()
  "Major mode for editing Perl code.
Expression and list commands understand all C brackets.
Tab indents for Perl code.
Paragraphs are separated by blank lines only.
Delete converts tabs to spaces as it moves back.

Various characters in Perl almost always come in pairs: {}, (), [],
sometimes <>. When the user types the first, she gets the second as
well, with optional special formatting done on {}.  You can always
quote (with \\[quoted-insert]) the left \"paren\" to avoid the
expansion. The processing of < is special, since most the time you
mean \"less\". Cperl mode tries to guess whether you want to type pair
<>, and inserts is if it appropriate. You can set
`electric-cperl-parens' to the string that contains the parenths  from
the above list you want to be electrical.

CPerl mode provides expansion of the Perl control constructs:
   if, else, while, until, for, and foreach.
The user types the keyword immediately followed by a space, which causes
the construct to be expanded, and the user is positioned where she is most
likely to want to be.
eg. when the user types a space following \"if\" the following appears in
the buffer:
            if () {
            }

and the cursor is between the parentheses.  The user can then type some
boolean expression within the parens.  Having done that, typing
\\[elec-c-linefeed] places you, appropriately indented on a new line
between the braces. If CPerl decides that you want to insert
\"English\" style construct like
            bite if angry;
it will not do any expansion.

\\[elec-c-linefeed] is a convinience replacement for typing carriage
return. It places you in the next line with proper indentation, or if
you type it inside the inline block of control construct, like

and you are on a boundary of a statement inside braces, it will
transform the construct into a multiline and will place you into an
apporpriately indented blank line.

\\{cperl-mode-map}

Setting the variable `cperl-font-lock' to nil switches off font-lock-mode,
`electric-cperl-lbrace-space' to nil switches off electric space
between $ and {,  `electric-cperl-parens' is the string that contains
parentheses that should be electric in CPerl.

Variables controlling indentation style:
 `cperl-tab-always-indent'
    Non-nil means TAB in CPerl mode should always reindent the current line,
...

read more »



Thu, 08 May 1997 11:51:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Emacs cperl-mode.el vs font-lock/lazy-lock

2. cperl-mode.el version for emacs21.1.1

3. Where can I find cperl-mode.el

4. cperl-mode.el troubles on XEmacs.

5. cperl-mode.el 1.8 available

6. Newer cperl-mode.el

7. Cperl-mode.el version 1.4

8. Newer version of cperl-mode.el

9. Cperl-mode.el customisation for parentheses

10. cperl-mode.el 1.8 available

11. cperl-mode.el

12. Wanted cperl-mode.el

 

 
Powered by phpBB® Forum Software