From owner-ntemacs-users@cs.washington.edu Tue Jul 29 12:54:29 1997 X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil] [nil "Tue" "29" "July" "1997" "15:10:12" "-0400" "Doug Campbell" "soup@ampersand.com" nil "188" "A Better Solution: perldb + emacs" "^From:" nil nil "7" nil nil nil nil] nil) Received: from joker.cs.washington.edu (joker.cs.washington.edu [128.95.1.42]) by june.cs.washington.edu (8.8.5+CS/7.2ju) with SMTP id MAA23270 for ; Tue, 29 Jul 1997 12:54:29 -0700 Received: from trout.cs.washington.edu (trout.cs.washington.edu [128.95.1.178]) by joker.cs.washington.edu (8.6.12/7.2ws+) with ESMTP id MAA36354 for ; Tue, 29 Jul 1997 12:54:27 -0700 Received: (majordom@localhost) by trout.cs.washington.edu (8.8.5+CS/7.2ws+) id MAA02692 for ntemacs-users-outgoing; Tue, 29 Jul 1997 12:15:09 -0700 (PDT) Received: from june.cs.washington.edu (june.cs.washington.edu [128.95.1.4]) by trout.cs.washington.edu (8.8.5+CS/7.2ws+) with ESMTP id MAA02650 for ; Tue, 29 Jul 1997 12:15:06 -0700 (PDT) Received: from ftp.ampersand.com (ftp.ampersand.com [192.156.188.2]) by june.cs.washington.edu (8.8.5+CS/7.2ju) with ESMTP id MAA19725 for ; Tue, 29 Jul 1997 12:15:05 -0700 Received: from dev.ampersand.com (tick [192.156.188.22]) by ftp.ampersand.com (8.8.3/8.8.3) with SMTP id PAA05906; Tue, 29 Jul 1997 15:14:56 -0400 (EDT) Received: from shift.ampersand.com by dev.ampersand.com (SMI-8.6/SMI-SVR4) id PAA24667; Tue, 29 Jul 1997 15:14:55 -0400 Message-Id: <3.0.1.32.19970729151012.006abe14@tick.ampersand.com> X-Sender: soup@tick.ampersand.com X-Mailer: Windows Eudora Pro Version 3.0.1 (32) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_870217812==_" Precedence: bulk From: Doug Campbell Sender: owner-ntemacs-users@cs.washington.edu To: ntemacs-users@cs.washington.edu, perl5-porters@perl.org Subject: A Better Solution: perldb + emacs Date: Tue, 29 Jul 1997 15:10:12 -0400 --=====================_870217812==_ Content-Type: text/plain; charset="us-ascii" --=====================_870217812==_ Content-Type: text/plain; charset="us-ascii" Summary ------- Here I show how to use the perl debugger with a modern emacs, using the latest emacs capabilities of gud and compilation modes. This works with Windows 95/NT as well as most unix variants. See "Directions" below to get started. Why the Change? --------------- In the past (emacs 18.x?) perl debugging was supported under emacs using a perldb.el file from the perl distribution that re-defined and duplicated much of the functionality of the emacs debugging and compilation capabilities with perl-specific versions. With newer emacs, the gud functions provide a language-independent way of running a debugger and the compilation mode functions provide a language-independent way of performing compilations. The problem is that the perl debugger requires both debugger support *and* compilation support simultaneously. Happily, this can be accomplished using compilation's minor mode capability under gud major mode. The code below performs this. I consider this an improvement over continuing to use perldb.el because future capabilities and fixes for gud and compilation mode will be available to perl debugger users, and perldb.el no longer has to be maintained as a duplicate effort. Usage ----- After installation, any buffer containing perl code can be run through perldb (in gud mode) by running the command "better-perldb". To visit the next compilation error, use C-x` (as usual), which will put the gud buffer in compilation minor mode. When done visiting compilation errors and/or warnings, use C-xx in the gud buffer to get out of compilation minor mode and back to debugger bindings. Remaining Issues ---------------- I can't get perltk windows to come up while running in the debugger under Windows 95. (Help, anyone?) Directions ---------- In addition to working on almost any unix-like configuration, the following directions also work for perl 5.004_01 and emacs 19.34.4 binary releases for Windows 95/NT. These can be obtained from: perl: ftp://ftp.digital.com/pub/plan/perl/CPAN/authors/Gurusamy_Sarathy/perl5.00401-bindist02-bc.tar.gz emacs: ftp.cs.washington.edu/pub/ntemacs/latest/i386/emacs-19.34.4-bin.tar.gz ftp.cs.washington.edu/pub/ntemacs/latest/i386/emacs-19.34.4-lisp.tar.gz 1. In /perl5db.pl, apply this patch: --------------------------- begin patch ------------------------------- *** perl5db.FCS Wed Jul 16 19:16:13 1997 --- perl5db.pl Wed Jul 16 19:14:47 1997 *************** *** 297,303 **** } # Around a bug: ! if (defined $ENV{OS2_SHELL} and ($emacs or $ENV{WINDOWID})) { # In OS/2 $console = undef; } --- 297,303 ---- } # Around a bug: ! if ((defined $ENV{OS2_SHELL} or $^O eq 'MSWin32') and ($emacs or $ENV{WINDOWID})) { # In OS/2 $console = undef; } ---------------------------- end patch ------------------------------- 2. Run the following emacs code (in your .emacs or whatever) --------------------------- begin code ------------------------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; perl debugger support ;;; Have to fix up compilation mode for perl (require 'compile) ;; Add the regex for looking for perl compile errors (defvar perl-compilation-error-regexp-alist ;; This looks like a paranoiac regexp: could anybody find a better one? '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]" 2 3)) "Alist that specifies how to match errors in perl output.") (setq compilation-error-regexp-alist (append compilation-error-regexp-alist perl-compilation-error-regexp-alist)) ;; Make compilation mode think that gud buffers are OK for error parsing. (defsubst compilation-buffer-p (buffer) (save-excursion (set-buffer buffer) (or (or compilation-minor-mode (eq major-mode 'compilation-mode)) (eq major-mode 'gud-mode)))) ;;; Have to fix up gud mode for perl (require 'gud) ;; Re-define gud-perldb-massage-args to handle variable perl flags (defvar gud-perldb-interp-flags "-dw" "The flags to pass to the perl interpreter when running a debug session.") (defun gud-perldb-massage-args (file args) (cons gud-perldb-interp-flags (cons (car args) (cons "-emacs" (cdr args))))) ;; Fix for perldb - make default reasonable and allow no-prompt option (defun better-perldb (&optional arg) "Runs perldb with better handling of default command string. With arg true, doesn't prompt for new command, uses last one." (interactive) (if (not (null arg)) (perldb (car gud-perldb-history)) (perldb (read-from-minibuffer "Run perldb (like this): " (if (and (consp gud-perldb-history) (string-match (concat "^ *[^ ]+ +" (buffer-file-name)) (car gud-perldb-history))) (car gud-perldb-history) (concat "perl " (buffer-file-name))) nil nil '(gud-perldb-history . 1))))) ;; Add functions that do compilation error matching using compilation mode, ;; then switch back when done. (C-x` for next-error, C-xx to exit) (defun perl-next-error () "Moves to the next perl error from the last perldb run." (interactive) (next-error)) (defun perl-next-error-start () "Moves to the next perl error from the last perldb run." (interactive) (compilation-minor-mode) (define-key (current-local-map) "\C-x`" 'perl-next-error) (define-key (current-local-map) "\C-xx" 'perl-next-error-end) (next-error)) (defun perl-next-error-end () "Ends compilation mode for finding perl errors and returns to perldb mode." (interactive) (set-buffer (compilation-find-buffer)) (compilation-minor-mode)) (defun perldb-compilation-preferences () (define-key (current-local-map) "\C-x`" 'perl-next-error-start)) (add-hook 'perldb-mode-hook '(lambda () (perldb-compilation-preferences))) ---------------------------- end code -------------------------------- What the Code Does ------------------ The patch to perl5db.pl in step 1 above makes perl use stdout for debugger messages instead of a console if it's running on Windows under emacs (otherwise it hangs). In step 2 above, the first part enhances compilation mode by allowing it to recognize perl errors and to use gud buffers as sources of compilation errors. The next part enhances gud mode by allowing arbitrary flags to be passed to the perl interpreter (including the all-important "-w" in the default) and making the default command line for perl include the proper file name. The last part adds the key bindings to get into compilation mode with C-x` and get out again with C-xx. Enjoy, Doug Campbell soup@ampersand.com --=====================_870217812==_--