Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

  1. ;; Copyright (C) 2016-2018 Free Software Foundation, Inc
  2. ;; Author: Rocky Bernstein <rocky@gnu.org>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. (require 'load-relative)
  12. (require 'comint)
  13. (require 'eshell)
  14. (defun realgud:strip (str)
  15. "Remove leading and tailing whitespace from STR."
  16. (while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'"
  17. str)
  18. (setq str (replace-match "" t t str)))
  19. str)
  20. ;; From http://rosettacode.org/wiki/Flatten_a_list#Emacs_Lisp
  21. (defun realgud:flatten (mylist)
  22. (cond
  23. ((null mylist) nil)
  24. ((atom mylist) (list mylist))
  25. (t
  26. (append (realgud:flatten (car mylist)) (realgud:flatten (cdr mylist))))))
  27. (if (or (< emacs-major-version 24)
  28. (and (= emacs-major-version 24) (<= emacs-minor-version 3)))
  29. ;; From
  30. ;; https://stackoverflow.com/questions/12999530/is-there-a-function-that-joins-a-string-into-a-delimited-string
  31. (defun realgud:join-string (list joiner)
  32. (mapconcat 'identity list joiner))
  33. (progn
  34. (require 'subr-x)
  35. (defalias 'realgud:join-string 'string-join)))
  36. (defun realgud:canonic-major-mode()
  37. "Return
  38. - 'eshell if we are in eshell-mode,
  39. - 'comint if the major comint-mode or shell-mode
  40. Or raise an error if neither."
  41. (cond ((derived-mode-p 'eshell-mode)
  42. 'eshell)
  43. ((derived-mode-p 'comint-mode)
  44. 'comint)
  45. ('t (error "We can only handle comint, shell, or eshell buffers"))
  46. ))
  47. (defun realgud:remove-ansi-schmutz()
  48. "Remove ASCII escape sequences that node.js 'decorates' in
  49. prompts and interactive output with"
  50. (interactive "")
  51. (add-to-list
  52. 'comint-preoutput-filter-functions
  53. (lambda (output)
  54. (replace-regexp-in-string "\033\\[[0-9]*[CDGKJhl]" "" output)))
  55. )
  56. (provide-me "realgud-")