Permalink
Browse files

Add utility commands, moved shell enhancement to their own file.

  • Loading branch information...
jimweirich committed Aug 18, 2011
1 parent 0fd4498 commit cba1a03b0102ff3e880af6f152f956bb78a5112b
Showing with 62 additions and 29 deletions.
  1. +33 −0 shell-enhancements.el
  2. +29 −29 utils.el
View
@@ -0,0 +1,33 @@
+(defun jw-choose-shell (n)
+ (let* ((shell-name (concat "*shell-" (number-to-string n) "*"))
+ (buf (get-buffer shell-name)))
+ (if (null buf)
+ (progn
+ (setq buf (shell))
+ (rename-buffer shell-name)))
+ (pop-to-buffer buf)
+ (goto-char (point-max))))
+
+(defun jw-shell (n)
+ (interactive "P")
+ (cond ((null n) (jw-choose-shell 0)) ; no prefix
+ ((atom n) (jw-choose-shell n)) ; numeric prefix
+ (t (jw-choose-shell 1)) )) ; ^U prefix
+
+(defun send-shell-command (str)
+ "Send commands to a shell process"
+ (let* ((proc (get-buffer-process (current-buffer)))
+ (pmark (process-mark proc)))
+ (insert-string str)
+ (insert-string "\n")
+ (set-marker pmark (point))
+ (comint-send-string proc (concat str "\n"))))
+
+(defun jw-suggest-width ()
+ (interactive)
+ (let ((wwidth (window-width (selected-window))))
+ (concat "export COLUMNS=" (number-to-string wwidth))))
+
+(defun jw-set-width ()
+ (interactive)
+ (send-shell-command (jw-suggest-width)))
View
@@ -1,35 +1,35 @@
;;; Some utility function
-(defun jw-choose-shell (n)
- (let* ((shell-name (concat "*shell-" (number-to-string n) "*"))
- (buf (get-buffer shell-name)))
- (if (null buf)
- (progn
- (setq buf (shell))
- (rename-buffer shell-name)))
- (pop-to-buffer buf)
- (goto-char (point-max))))
-
-(defun jw-shell (n)
- (interactive "P")
- (cond ((null n) (jw-choose-shell 0)) ; no prefix
- ((atom n) (jw-choose-shell n)) ; numeric prefix
- (t (jw-choose-shell 1)) )) ; ^U prefix
-
-(defun send-shell-command (str)
- "Send commands to a shell process"
- (let* ((proc (get-buffer-process (current-buffer)))
- (pmark (process-mark proc)))
- (insert-string str)
- (insert-string "\n")
- (set-marker pmark (point))
- (comint-send-string proc (concat str "\n"))))
+(defun undos ()
+ "Remove the <CR> in DOS files"
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (replace-string "
+" "")
+ (goto-char (point-min))
+ (replace-string "" "") ))
-(defun jw-suggest-width ()
+(defun unansi ()
+ "Remove the ansi markup in files"
(interactive)
- (let ((wwidth (window-width (selected-window))))
- (concat "export COLUMNS=" (number-to-string wwidth))))
+ (save-excursion
+ (goto-char (point-min))
+ (replace-regexp "\\([\\[0-9;\\]*m\\|\r\\)" "")
+ ))
-(defun jw-set-width ()
+(defun unhtml ()
+ "Remove the HTML tags in a file"
(interactive)
- (send-shell-command (jw-suggest-width)))
+ (save-excursion
+ (goto-char (point-min))
+ (replace-regexp "<[^>]*>" "")
+ (goto-char (point-min))
+ (replace-string "&nbsp;" " ")
+ (goto-char (point-min))
+ (replace-string "&lt;" "<")
+ (goto-char (point-min))
+ (replace-string "&gt;" ">")
+ (goto-char (point-min))
+ (replace-string "&amp;" "&") ))
+

0 comments on commit cba1a03

Please sign in to comment.