Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Learning Emacs

by artist (Parson)
on Oct 18, 2001 at 23:51 UTC ( #119779=perlquestion: print w/replies, xml ) Need Help??

artist has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have started to learn Emacs editor. Having worked in plenty of other editor for many number of years, I am surprised why I never bother to learn emacs. I liked the powerful M-x command and modes. What I liked the most about it is the text commands expansion and lookup, so you know that what the command is meant for. I once thought that similar functionality can be used for perl functions. Especailly for newbies, it would be extremely useful.
Imagine
 M-x join-with-coma-default-array
will put
join ',' => @_;
And then bind a key to this( may be not to this but to some complex one). This can also serve good purpose for documentation. Of course, it will require some patience for someone to write all these but effort may worth something. You got the idea.

I was just wondering as how you are using emacs while programming perl. What sort of task you consider more rightly done in emacs.
Thanks,
Artist.

Replies are listed 'Best First'.
Re: Learning Emacs
by stefan k (Curate) on Oct 19, 2001 at 12:37 UTC
    Hi,
    if I hadn't my highly personalized xemacs I wouldn't know how to survive. Acutally XEmacs, xterm, mozilla ruby and perl make up at least 95% of my work time :)

    Anyway... Lemme get to the fun stuff.

    Skeletons

    First I'd like to sent you to my node (X)Emacs Skeletons and Auto-Insert, where I show off some skeletons. You need to know that skeletons are extremely powerful templates. I abandoned all the keyboard macros I once recorded and organized plus any abbrevs that may have been there in favour of skeletons because they're just _it_.

    An Explanation Plus An Example

    (define-skeleton ska-skel-perl-sub "Insert a perl subroutine with arguments." "Subroutine name: " "sub " str " {" \n "my (" ("Argument name: " "$" str ", ") -2 ") = @_;" "\n" \n _ \n "}" '(progn (indent-according-to-mode) nil) \n)
    This defines an elisp function called ska-skel-perl-sub which then inserts a perl sub template. You can bind this function to a key in the usual way(s), e.g.:
    (local-set-key '[(control b) (control s)] 'ska-skel-perl-sub)
    (keep in mind that this must be called from the appropriate hook - see below).

    The overall structure of a skeleton is:
    (define-skeleton ska-skel-perl-sub This defines the name to use
    "Insert a perl subroutine with arguments." A documentation string, which gets prepended to the general skelton docs when you call C-h f ska-skel-perl-sub
    "Subroutine name: " This is a prompt for a string (without any TAB completion). The string you put in here is later available as str, but if you don't need any user information you might as well put nil here.
    All later stuff is either inserted or interpreted.

    Special Sequences

    There are several special strings in a skeleton:
    str
    The string the user gave at the prompt
    \n
    Insert current line according to mode and newline (this doesn't work always correctly)
    >
    indent current line
    _
    position the cursor shall be when skeleton is done. I sometimes encounter problems with this, too
    - num
    delete num chars leftwards
    & and |
    logical and and or. When the preceding command has moved the point & will do the next thing whereas | does the usual logical or stuff (like you know from the shell...)
    Of course there is even more. For example an opening brace introduces a new recursive skeleton which may ask for a string again (used in the above example), or you may execute some lisp code (usually by putting it into a progn statement, and returning </code>nil</code>!) and whatevermore.

    See C-h f skeleton-insert for docs and sh-script.el or skeleton.el for examples (I think the ada-mode contained some examples, too)

    Hooks

    The main emacs way of customizing modes is by using the appropriate hooks. A hook is a piece of code that get's executed (e.g.) when a mode connected with that hook is entered. A Perl Mode Hook may look like this:
    (setq cperl-mode-hook '(lambda () ;; my keybindings (ska-coding-keys cperl-mode-map) (ska-cperl-mode-keys) (auto-fill-mode 1) ;; if you don't want tabs ;;(setq indent-tabs-mode nil) ;; full featured mode: (setq cperl-hairy t) ;; alternatively: ;;(setq cperl-auto-newline-after-colon t) ;;(setq cperl-electric-parens "({[") (setq cperl-auto-newline t) (setq cperl-electric-linefeed t) ))
    Here I call a function that sets up some functions available for all modes I use (ska-coding-keys), the special perl keybindings, turn on the auto-fill which breaks lines at a certain column (C-h v fill-column) and make the perl mode very active so that it inserts all kinds of stuff automatically (this is definitely a matter of taste! I hate it in C-Mode but in perl for me it's fine).

    Just to make this posting kind of complete I provide (some of) the missing function and offer to sent you my complete emacs setup per email (drop me a /msg with your adress)

    Update: Added READMORE tag (taking into account what has been said :)

    If you want (almost) all code:

Re: Learning Emacs
by premchai21 (Curate) on Oct 19, 2001 at 00:55 UTC

    Er, join-with-coma? I think you mean join-with-comma. But note that if you know some Emacs Lisp, you can do much more powerful stuff; it's a programming language in itself. If you have CPerl mode (comes with XEmacs), then under the CPerl menu, or from the extended-command line (not the extended command-line!), you can perldoc modules, functions, and FAQs and have the documentation displayed in a separate buffer in manual page mode. If you're running under X with a 104-key keyboard you get menu eq M-x (at least under XEmacs), and by reconfiguring X you can reassign the physical modifier keys to different logical modifier keys; you can really get some interesting chords then -- think having to use both hands (and possibly your head, if you bind the big modifier chord plus a mouse button). Also, sequences of keys can be bound.

    And of course you can extend, and extend, and extend. Write your own modes and other functions if you don't like the ones that exist; write full applications if they work well in Emacs.

    This is probably going to start a holy war, but...

    All Hail XEmacs!

Re: Learning Emacs
by Sweeper (Pilgrim) on Oct 19, 2001 at 09:46 UTC
    Do you know that John Tobey has written two modules that allow you to use Perl inside Emacs procedures? You still need to learn Emacs-Lisp, but you do not write Lisp programs. You write Perl programs that call Emacs-Lisp functions.

    One additional note: I could not install Perlmacs, but one the other side EPL runs fine on my Emacs.

    Another additional note: for very short functions, just use Lisp. But for more than, say, 5 or 6 lines, I prefer to use Perl with EPL.

    Oops, I forgot John Tobey's: http://www.perl.com/CPAN-local/modules/by-authors/id/J/JT/JTOBEY/

Re: Learning Emacs
by moodster (Hermit) on Oct 19, 2001 at 15:35 UTC
    When programming in Emacs, I found that the single most useful feature was dabbrev-expand (and perhaps the closely related hippie-expand), which takes a look at what you're currently typing and tries to complete the word by analyzing the text in your other open buffers. I mapped the command to that silly little key above the tab key and used it all the time.

    I later switched to vim (mostly for the sake of trying a new coding environment) and this is the feature I miss most. The autocomplete in vim... well it doesn't suck but it's not really the same.

    Oh, I almost forgot, check out dotfiles.com for a collection of useful init files and macros. I hope you realize that from now on your life will be a quest for the ultimate .emacs ... :)

Re: Learning Emacs
by Fletch (Chancellor) on Oct 19, 2001 at 06:57 UTC

    You should check out abbrev mode. It allows you to setup abbreviations (hence `abbrev') that will be expanded for you on the fly as you type. Check the emacs (or xemacs) info file (C-h i m emacs RET) for the section titled `Abbrevs'.

    ORA has several emacs related books you might want to check out, such as these:

YA auto completion module (was Re: Learning Emacs)
by stefp (Vicar) on Oct 19, 2001 at 19:20 UTC
    I am searching an elisp module I once used. For professional reason I had to use vi and lost track about the said elisp module. It does a special form of autocompletion best explained by example: M-X q-r-r TAB would give M-X query-replace-regexp
    Instead of completing on the whole word, it breaks it on the dash and try to complete all the parts so that when reasembled it makes the name of a command. This should not be too difficult to write for someone who is proficient in elisp. I am not. And probably this module is out somewhere on the net. But Where?

    -- stefp

      Hi Stefp
      I just came acorss what you were looking for
      Look at M-x partial-completion-mode
      I am using gnu emacs 21.2.1

      Showing art of faster completion,
      Artist

        Thank you very much. I should have thought it could have made the core and do a C-h a completion to search it. I found that if I use bindings, first I need to remember the binding and eventually I lose the name of the underlying command. With partial completion, I get to remember the underlying command without typing to much.

        -- stefp -- check out TeXmacs wiki

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://119779]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-01-25 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (66 votes). Check out past polls.

    Notices?