home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / patches / mh-unshar.patch < prev    next >
Encoding:
Text File  |  1991-06-14  |  4.5 KB  |  128 lines

  1. Path: dg-rtp!rock.concert.net!mcnc!stanford.edu!bu.edu!lll-winken!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage
  2. From: darrylo@HPNMXX.SR.HP.COM (Darryl Okahata)
  3. Newsgroups: gnu.emacs.sources
  4. Subject: Another mh-e.el enhancement
  5. Date: 11 Jun 91 00:24:43 GMT
  6. Organization: Source only  Discussion and requests in gnu.emacs.help.
  7.  
  8.  
  9.      Here is a patch to V18.57 mh-e.el that allows you to unshar mailed
  10. shar files from within mh-e.  In the scan window, you simply move the
  11. cursor to the message that containing the shar file and press M-n (for
  12. "uNshar" -- I'm sorry that I couldn't find a better keybinding, but all
  13. the others were taken).  You will be prompted for the name of the
  14. directory in which to unshar the archive.
  15.  
  16.      This function works by searching for the beginning of the shar file
  17. in the mail message, using the following technique:
  18.  
  19. 1. Look for the regexp "^#![ \t]*/bin/sh".
  20.  
  21. 2. If that is not found, look for the regexp "^[^a-z0-9\"]*cut here".
  22.    This regexp will, hopefully, only match the real "cut here" line, and
  23.    not the phrase "cut here" in a preamble.
  24.  
  25. 3. If that is not found, look for a line that begins with "#".
  26.  
  27. 4. If that is not found, look for a line that begins with ":".
  28.  
  29.      The only problem is that this function does the unshar in the
  30. foreground.  It would be nice if it could occur in the background.
  31.  
  32.      Note also that these patches are relative to my modified version of
  33. mh-e.el, whose patches I posted earlier (if anyone missed them, and
  34. would like a copy, send email).  I don't think that these patches will
  35. apply to vanilla V18.57 mh-e.el, but I haven't tried it (fortunately,
  36. these patches are trivial to apply by hand).
  37.  
  38.      -- Darryl Okahata
  39.     Internet: darrylo@sr.hp.com
  40.  
  41. DISCLAIMER: this message is the author's personal opinion and does not
  42. constitute the support, opinion or policy of Hewlett-Packard or of the
  43. little green men that have been following him all day.
  44.  
  45. ===============================================================================
  46. *** mh-e.el.~5~    Thu May 30 10:49:09 1991
  47. --- mh-e.el    Thu Jun  6 14:21:39 1991
  48. ***************
  49. *** 2960,2965
  50.       )
  51.     )
  52.   
  53.   
  54.   
  55.   ;;; Build the folder-mode keymap:
  56.  
  57. --- 2960,3012 -----
  58.       )
  59.     )
  60.   
  61. + (defun mh-unshar (dir)
  62. +   "Unshar the current message in the directory given by DIR."
  63. +   (interactive "DUnshar in directory: ")
  64. +   (let ((default-directory default-directory)
  65. +         (errbuf " *Unshar Output*")
  66. +     (curbuf (current-buffer))
  67. +     (show-buffer mh-show-buffer)
  68. +     start
  69. +     )
  70. +     (setq dir (expand-file-name dir))
  71. +     (if (not (eq system-type 'vax-vms))
  72. +     (setq dir (file-name-as-directory dir)))
  73. +     (mh-show nil)        ;;; force showing of current message
  74. +     (save-excursion
  75. +       (set-buffer show-buffer)
  76. +       (goto-char (point-min))
  77. +       (message "Looking for start of shar package ...")
  78. +       (if (or (re-search-forward "^#![ \t]*/bin/sh" nil t)
  79. +           (and (re-search-forward "^[^a-z0-9\"]*cut here" nil t)
  80. +            (forward-line 1))
  81. +           (re-search-forward "^#" nil t)
  82. +           (re-search-forward "^: " nil t)
  83. +           )
  84. +       (progn
  85. +         (beginning-of-line)
  86. +         (setq start (point))
  87. +         (set-buffer curbuf)
  88. +         (pop-to-buffer errbuf)
  89. +         (kill-region (point-max) (point-min))
  90. +         (insert (format "Unsharing in directory \"%s\" ...\n\n" dir))
  91. +         (message "Please wait ...")
  92. +         (sit-for 0)
  93. +         (set-buffer show-buffer)
  94. +         (setq default-directory dir)
  95. +         (call-process-region start (point-max)
  96. +                  "/bin/sh" nil errbuf t)
  97. +         (pop-to-buffer curbuf)
  98. +         (message "Unshar done")
  99. +         )
  100. +     (error "Can't find start of shar file")
  101. +     )
  102. +       )
  103. +     )
  104. +   )
  105.   
  106.   
  107.   ;;; Build the folder-mode keymap:
  108. ***************
  109. *** 2984,2989
  110.   (define-key mh-folder-mode-map "\ef" 'mh-visit-folder)
  111.   (define-key mh-folder-mode-map "\ek" 'mh-kill-folder)
  112.   (define-key mh-folder-mode-map "\el" 'mh-list-folders)
  113.   (define-key mh-folder-mode-map "\eo" 'mh-write-msg-to-file)
  114.   (define-key mh-folder-mode-map "\ep" 'mh-pack-folder)
  115.   (define-key mh-folder-mode-map "\eq" 'mh-list-sequences)
  116.  
  117. --- 3031,3037 -----
  118.   (define-key mh-folder-mode-map "\ef" 'mh-visit-folder)
  119.   (define-key mh-folder-mode-map "\ek" 'mh-kill-folder)
  120.   (define-key mh-folder-mode-map "\el" 'mh-list-folders)
  121. + (define-key mh-folder-mode-map "\en" 'mh-unshar)
  122.   (define-key mh-folder-mode-map "\eo" 'mh-write-msg-to-file)
  123.   (define-key mh-folder-mode-map "\ep" 'mh-pack-folder)
  124.   (define-key mh-folder-mode-map "\eq" 'mh-list-sequences)
  125.