em-xtra.el 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ;;; em-xtra.el --- extra alias functions -*- lexical-binding:t -*-
  2. ;; Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. ;; Author: John Wiegley <johnw@gnu.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;; Code:
  17. (require 'esh-util)
  18. (eval-when-compile
  19. (require 'eshell)
  20. (require 'pcomplete))
  21. (require 'compile)
  22. ;;;###autoload
  23. (progn
  24. (defgroup eshell-xtra nil
  25. "This module defines some extra alias functions which are entirely
  26. optional. They can be viewed as samples for how to write Eshell alias
  27. functions, or as aliases which make some of Emacs's behavior more
  28. naturally accessible within Emacs."
  29. :tag "Extra alias functions"
  30. :group 'eshell-module))
  31. ;;; Functions:
  32. (autoload 'eshell-parse-command "esh-cmd")
  33. (defun eshell/expr (&rest args)
  34. "Implementation of expr, using the calc package."
  35. (if (not (fboundp 'calc-eval))
  36. (throw 'eshell-replace-command
  37. (eshell-parse-command "*expr" (eshell-flatten-list args)))
  38. ;; to fool the byte-compiler...
  39. (let ((func 'calc-eval))
  40. (funcall func (eshell-flatten-and-stringify args)))))
  41. (defun eshell/substitute (&rest args)
  42. "Easy front-end to `intersection', for comparing lists of strings."
  43. (apply 'substitute (car args) (cadr args) :test 'equal
  44. (cddr args)))
  45. (defun eshell/count (&rest args)
  46. "Easy front-end to `intersection', for comparing lists of strings."
  47. (apply 'count (car args) (cadr args) :test 'equal
  48. (cddr args)))
  49. (defun eshell/mismatch (&rest args)
  50. "Easy front-end to `intersection', for comparing lists of strings."
  51. (apply 'mismatch (car args) (cadr args) :test 'equal
  52. (cddr args)))
  53. (defun eshell/union (&rest args)
  54. "Easy front-end to `intersection', for comparing lists of strings."
  55. (apply 'union (car args) (cadr args) :test 'equal
  56. (cddr args)))
  57. (defun eshell/intersection (&rest args)
  58. "Easy front-end to `intersection', for comparing lists of strings."
  59. (apply 'intersection (car args) (cadr args) :test 'equal
  60. (cddr args)))
  61. (defun eshell/set-difference (&rest args)
  62. "Easy front-end to `intersection', for comparing lists of strings."
  63. (apply 'set-difference (car args) (cadr args) :test 'equal
  64. (cddr args)))
  65. (defun eshell/set-exclusive-or (&rest args)
  66. "Easy front-end to `intersection', for comparing lists of strings."
  67. (apply 'set-exclusive-or (car args) (cadr args) :test 'equal
  68. (cddr args)))
  69. (defalias 'eshell/ff 'find-name-dired)
  70. (defalias 'eshell/gf 'find-grep-dired)
  71. (defun pcomplete/bcc32 ()
  72. "Completion function for Borland's C++ compiler."
  73. (let ((cur (pcomplete-arg 0)))
  74. (cond
  75. ((string-match "\\`-w\\([^;]+;\\)*\\([^;]*\\)\\'" cur)
  76. (pcomplete-here
  77. '("ali" "amb" "amp" "asc" "asm" "aus" "bbf" "bei" "big" "ccc"
  78. "cln" "cod" "com" "cpt" "csu" "def" "dig" "dpu" "dsz" "dup"
  79. "eas" "eff" "ext" "hch" "hid" "ias" "ibc" "ifr" "ill" "nil"
  80. "lin" "lvc" "mcs" "mes" "mpc" "mpd" "msg" "nak" "ncf" "nci"
  81. "ncl" "nfd" "ngu" "nin" "nma" "nmu" "nod" "nop" "npp" "nsf"
  82. "nst" "ntd" "nto" "nvf" "obi" "obs" "ofp" "osh" "ovf" "par"
  83. "pch" "pck" "pia" "pin" "pow" "prc" "pre" "pro" "rch" "ret"
  84. "rng" "rpt" "rvl" "sig" "spa" "stl" "stu" "stv" "sus" "tai"
  85. "tes" "thr" "ucp" "use" "voi" "zdi") (match-string 2 cur)))
  86. ((string-match "\\`-[LIn]\\([^;]+;\\)*\\([^;]*\\)\\'" cur)
  87. (pcomplete-here (pcomplete-dirs) (match-string 2 cur)))
  88. ((string-match "\\`-[Ee]\\(.*\\)\\'" cur)
  89. (pcomplete-here (pcomplete-dirs-or-entries "\\.[Ee][Xx][Ee]\\'")
  90. (match-string 1 cur)))
  91. ((string-match "\\`-o\\(.*\\)\\'" cur)
  92. (pcomplete-here (pcomplete-dirs-or-entries "\\.[Oo][Bb][Jj]\\'")
  93. (match-string 1 cur)))
  94. (t
  95. (pcomplete-opt "3456ABCDEHIKLMNOPRSTUVXabcdefgijklnoptuvwxyz"))))
  96. (while (pcomplete-here
  97. (pcomplete-dirs-or-entries "\\.[iCc]\\([Pp][Pp]\\)?\\'"))))
  98. (defalias 'pcomplete/bcc 'pcomplete/bcc32)
  99. (provide 'em-xtra)
  100. ;; Local Variables:
  101. ;; generated-autoload-file: "esh-groups.el"
  102. ;; End:
  103. ;;; em-xtra.el ends here