Emacs Perl addons: cooperate with h2xs 
Author Message
 Emacs Perl addons: cooperate with h2xs

Has anyone created any utilities for easier testing and debugging
under Emacs of Perl modules which were created using h2xs?

For example, I insert stuff like the following at the end of every
t/*.t file:

/----
| # Local Variables:
| # compile-command: "cd ..; echo foo.t: Entering directory \\``pwd`\\'; perl -w -I lib t/foo.t"
| # End:
\----

And for M-x perldb RET I always have to change the command for running
the de{*filter*}, too: I have to add the right -I options and stuff.

And I have added stuff to the compilation-error-regexp-alist so that
M-x next-error RET doesn't pick files from the blib directory:

/----
| (require 'compile)
| (setq compilation-error-regexp-alist
|       (append compilation-error-regexp-alist
|               '((".* at blib/\\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 1 2))))
\----

Does anybody have stuff like this?

kai
--
Be indiscrete.  Do it continuously.



Sun, 03 Aug 2003 20:50:12 GMT  
 Emacs Perl addons: cooperate with h2xs

Quote:

> Has anyone created any utilities for easier testing and debugging
> under Emacs of Perl modules which were created using h2xs?

> For example, I insert stuff like the following at the end of every
> t/*.t file:

> /----
> | # Local Variables:
> | # compile-command: "cd ..; echo foo.t: Entering directory \\``pwd`\\'; perl -w -I lib t/foo.t"
> | # End:
> \----

> And for M-x perldb RET I always have to change the command for running
> the de{*filter*}, too: I have to add the right -I options and stuff.

So it looks like you're taking a short-cut by directly debugging
and possibly editing out bugs from the source in lib instead of
the blib area that gets built by make.

To facilitate M-x perldb and the use of your compile-command on
the ".t" files, how about adding the following to all the ".t"
files?

    use lib "../lib";

Quote:
> Does anybody have stuff like this?

Here's a version of the emacs perldb mode that I've been maintaining
for myself and co-workers.  It provides features that don't come with
the standard emacs perldb mode (e.g. perldb-next-error and minibuffer
filename completion).

;;; perldb+.el --- an enhanced perl debugging mode

;; Copyright (C) 1988,1990,1997,2000 Free Software Foundation, Inc.

;; Author: W. Schelter, Ray Lischner

;; Keywords: de{*filter*}, perl
;; Version: 1.04

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

;;; Commentary:

;; Description
;; ===========
;; Perldb+ provides an interface to Perl's de{*filter*} (perl -dw) within
;; emacs.  This implementation of perldb is an alternative to the one
;; that comes with emacs as part of the GUD library (Grand Unified
;; De{*filter*}).  It contains a feature to position to where syntax
;; errors or warnings occur in the source.  It also provides
;; minibuffer filename completion when entering the perl source to
;; debug.  It is known to work with Emacs versions 19-20, XEmacs
;; versions 19-20, and Emacs 19.34 for NT/95.
;;
;;
;; Installation
;; ============
;; Copy or move this file to a file called perldb+.el in a lisp
;; directory known to emacs (see emacs variable `load-path').
;; Optionally byte compile it (you can ignore warnings about "free
;; variables").  Put the following in a startup file such as your
;; ~/.emacs
;;
;;   (autoload 'perldb "perldb+" "Major mode for running the perl de{*filter*}." t)
;;   (eval-after-load "gud" '(load "perldb+" t t))
;;
;;
;; Usage
;; =====
;; Use M-x perldb to invoke.  You are prompted for the Perl source to
;; debug and its command line arguments.  When invoked with a prefix
;; argument then the current buffer is the default source to debug.
;; The perl interpreter is started in debug mode and displayed in its
;; own buffer using `perldb-command-name' and `perldb-command-args'.
;; Change these variables to use a different perl interpreter with
;; different command line switches.  Their defaults are "perl" and
;; "-dw".
;;
;; The source is displayed in another buffer with an arrow (`=>')
;; indicating the next line of execution.  If there are compilation
;; errors then iteratively use the command `C-x `' to visit the
;; location of each error in the source.
;;
;;
;; Special Notes for MS-Win32
;; ==========================
;; For MS-Windows NT/95 and perl version 5.004_01 or version 5.001 and
;; less, the de{*filter*} doesn't work with emacs.  To fix, the perl
;; de{*filter*} itself must be patched.  Locate and change the code
;; similar to the following for the perl file lib/perl5db.pl.
;;
;;    if (-e "/dev/tty") {
;;        $console = "/dev/tty";
;;        $rcfile=".perldb";
;;    }
;;    elsif (-e "con") {
;;        $console = "";                 <---- change "con" to ""
;;        $rcfile="perldb.ini";
;;    }
;;    else {
;;        $console = "sys\$command";
;;        $rcfile="perldb.ini";
;;    }
;;
;;
;; History
;; =======
;; Perldb is based on gdb.el, as written by W. Schelter, and modified by rms.
;; It was modified for perl by Ray Lischner (uunet!mntgfx!lisch), Nov 1990.


;;
;;
;; Revisions
;; =========
;;
;; 1.04 jr:
;;      When running under MS-Windows, set PERL5DB env so ActiveState
;;      de{*filter*} doesn't start.
;;
;; 1.03 jr:
;;     When prompting for a program and arguments to debug, minibuffer
;;     defaults are supplied and a perldb specific minibuffer history
;;     is used.
;;
;;     Added "customization" support for the perldb+ user options.
;;
;;     Squelched backtrace on warnings nonsense from perl de{*filter*} by
;;     appending env PERLDB_OPTS with "warnLevel=0".
;;
;;     Fixed bug exposed by new version of comint.el in Emacs 20.3.
;;
;; 1.02 jr:
;;     Renamed to perldb+.el to distinguish from the one that comes
;;     with an emacs distribution.
;;
;; 1.01 jr:
;;     Baselined version.

;;; Code:

(require 'comint)

(cond ((and (fboundp 'defgroup) (fboundp 'defcustom))
       (defgroup perldb+ nil
         "Major mode for interacting with the perl de{*filter*}."
         :group 'unix
         :group 'tools)
       (defcustom perldb-command-name "perl"
         "Pathname of Perl interpreter."
         :type 'string
         :group 'perldb+)
       (defcustom perldb-command-args "-dw"
         "Switches to run perl as de{*filter*}."
         :type 'string
         :group 'perldb+))
      (t
       (defvar perldb-command-name "perl"
         "*Pathname of Perl interpreter.")
       (defvar perldb-command-args "-dw"
         "*Switches to run perl as de{*filter*}.")))

;; Shun ActiveState de{*filter*} when running on MS-Windows.
(if (or (string= "w32" window-system) (string= "win32" window-system))
    (setenv "PERL5DB" "BEGIN {require 'perl5db.pl'}"))

;; Turn-off perl de{*filter*}'s silly backtrace on warnings.
(setenv "PERLDB_OPTS" (if (> (length (getenv "PERLDB_OPTS")) 0)
                          (concat (getenv "PERLDB_OPTS") " warnLevel=0")
                        "warnLevel=0"))

(defvar perldb-dos-binmode (and (string= system-type "windows-nt")
                                (boundp 'emacs-major-version)
                                (= emacs-major-version 19)
                                (<= emacs-minor-version 34))
  "*This flag turns on a work around for a problem on MS-Win32 machines
   where emacs hangs before displaying a de{*filter*} prompt.  This
   problem is caused by the MS-Win32 I/O routines interpreting ^Z as
   end-of-file.  This problem is fixed in versions of emacs after 19.34.")

(defvar perldb-prompt-pattern "^  DB<+[0-9]+>+ "
  "A regexp to recognize the prompt for perldb.")

(defvar perldb-prg-name-history nil)
(defvar perldb-prg-name-alist nil)
(defvar perldb-prg-args-history nil)
(defvar perldb-last-frame nil)
(defvar perldb-last-frame-displayed-p nil)
(defvar perldb-delete-prompt-marker nil)
(defvar perldb-filter-accumulator nil)

(defvar perldb-mode-map nil
  "Keymap for perldb-mode.")

(if perldb-mode-map
    nil
  (setq perldb-mode-map (copy-keymap comint-mode-map))
  (define-key perldb-mode-map "\C-c\C-l" 'perldb-refresh))

(define-key ctl-x-map " " 'perldb-break)
(define-key ctl-x-map "&" 'send-perldb-command)
(define-key ctl-x-map "~" 'perldb-next-error)
(define-key perldb-mode-map "\M-n" 'comint-next-matching-input-from-input)
(define-key perldb-mode-map "\M-p" 'comint-previous-matching-input-from-input)
(define-key perldb-mode-map "\C-x`" 'perldb-next-error)
(if (boundp 'perl-mode-map)
    (define-key perl-mode-map "\C-x`" 'perldb-next-error)
  (add-hook 'perl-mode-hook
            '(lambda ()
               (define-key perl-mode-map "\C-x`" 'perldb-next-error))))
(if (boundp 'cperl-mode-map)
    (define-key cperl-mode-map "\C-x`" 'perldb-next-error)
  (add-hook 'cperl-mode-hook
            '(lambda ()
               (define-key cperl-mode-map "\C-x`" 'perldb-next-error))))

;;Of course you may use `def-perldb' with any other perldb command, including
;;user defined ones.

(defmacro def-perldb (name key &optional doc)
  (let* ((fun (intern (concat "perldb-" name))))
    (` (progn
         (defun (, fun) (arg)
           (, (or doc ""))
           (interactive "p")
           (perldb-call (if (not (= 1 arg))
                            (concat (, name) arg)
                          (, name))))
         (define-key perldb-mode-map (, key) (quote (, fun)))))))

(def-perldb "s"   "\M-s" "Step one source line with display")
(def-perldb "n"   "\M-n" "Step one source line (skip functions)")
(def-perldb "c"   "\M-c" "Continue with display")
;;(def-perldb "r"   "\C-c\C-r" "Return from current subroutine")
;;(def-perldb "A"   "\C-c\C-a" "Delete all actions")

(defun perldb-mode ()
  "Major mode for interacting with the perl de{*filter*}.
The following commands are available:

\\{perldb-mode-map}

You can then use the command \\[perldb-next-error] to find the next error
or warning message and move to the source code that caused it.

\\[perldb-display-frame] displays in the other window
the last line referred to in the perldb buffer.

\\[perldb-s],\\[perldb-n], and \\[perldb-n] in the perldb window,
call perldb to step, next or continue and then update the other window
with the current file and position.

If you are in a source file, you may select a point to break
at, by doing \\[perldb-break].

Commands:
Many commands are inherited from shell mode.
Additionally we have:

\\[perldb-display-frame] display frames file in other window
\\[perldb-s] advance one line in program
\\[perldb-n] advance one line in program (skip over calls).
\\[send-perldb-command] used for special printing of an ...

read more »



Tue, 05 Aug 2003 04:03:06 GMT  
 Emacs Perl addons: cooperate with h2xs

Quote:
> So it looks like you're taking a short-cut by directly debugging
> and possibly editing out bugs from the source in lib instead of
> the blib area that gets built by make.

Well, I don't really NEED that shortcut.  If you can tell me how to
circumvent this stuff?  Is it possible to tell GUD to open a different
file, rather than the one from the blib/ subdir?

I have already frobbed compilation-error-regexp-alist so that the
"blib/" part in the error messages is ignored, and the corresponding
file from the "lib/" subdir is loaded.  Of course, this fails for
those files which are preprocessed.  Hm.  I wish I had a real
solution, ie something which knows what is the right file, and also
something which knows how to convert the error message line numbers
into the line numbers in the source file.

Quote:
> To facilitate M-x perldb and the use of your compile-command on
> the ".t" files, how about adding the following to all the ".t"
> files?

>     use lib "../lib";

Ah, this might be a solution.  Nifty idea.

Quote:
> Here's a version of the emacs perldb mode that I've been maintaining
> for myself and co-workers.  It provides features that don't come
> with the standard emacs perldb mode (e.g. perldb-next-error and
> minibuffer filename completion).

Ah, I'll try this.

kai
--
Be indiscrete.  Do it continuously.



Tue, 05 Aug 2003 23:29:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. TDBGrid vs Oracle

2. Perl and tar not cooperating in a shell script

3. Addons for Popular perl Scripts

4. Cooperating processes...

5. Making OpenGL cooperate with pTk

6. Forum addons ie: bad words filter

7. Emacs::Lisp 0.3 and emacs-20.2 patch

8. Cached Updates: deleting records

9. HELP with TField

10. h2xs & perl module creation

11. ANN: Tut # 1 (reissued) Auto-generation of Perl module skeletons using h2xs

12. QUICK Help. h2xs Extending Perl Question

 

 
Powered by phpBB® Forum Software