patch-eshell-26.el 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;;; Fix bug#29157: 25.3; Eshell parsing fails sometimes [...]
  2. (with-eval-after-load 'em-hist
  3. (defun eshell-hist-initialize ()
  4. "Initialize the history management code for one Eshell buffer."
  5. ;; PATCH: Disable the history references.
  6. ;; (add-hook 'eshell-expand-input-functions
  7. ;; 'eshell-expand-history-references nil t)
  8. (when (eshell-using-module 'eshell-cmpl)
  9. (add-hook 'pcomplete-try-first-hook
  10. 'eshell-complete-history-reference nil t))
  11. (if (and (eshell-using-module 'eshell-rebind)
  12. (not eshell-non-interactive-p))
  13. (let ((rebind-alist eshell-rebind-keys-alist))
  14. (make-local-variable 'eshell-rebind-keys-alist)
  15. (setq eshell-rebind-keys-alist
  16. (append rebind-alist eshell-hist-rebind-keys-alist))
  17. (set (make-local-variable 'search-invisible) t)
  18. (set (make-local-variable 'search-exit-option) t)
  19. (add-hook 'isearch-mode-hook
  20. (function
  21. (lambda ()
  22. (if (>= (point) eshell-last-output-end)
  23. (setq overriding-terminal-local-map
  24. eshell-isearch-map)))) nil t)
  25. (add-hook 'isearch-mode-end-hook
  26. (function
  27. (lambda ()
  28. (setq overriding-terminal-local-map nil))) nil t))
  29. (define-key eshell-mode-map [up] 'eshell-previous-matching-input-from-input)
  30. (define-key eshell-mode-map [down] 'eshell-next-matching-input-from-input)
  31. (define-key eshell-mode-map [(control up)] 'eshell-previous-input)
  32. (define-key eshell-mode-map [(control down)] 'eshell-next-input)
  33. (define-key eshell-mode-map [(meta ?r)] 'eshell-previous-matching-input)
  34. (define-key eshell-mode-map [(meta ?s)] 'eshell-next-matching-input)
  35. (define-key eshell-command-map [(meta ?r)]
  36. 'eshell-previous-matching-input-from-input)
  37. (define-key eshell-command-map [(meta ?s)]
  38. 'eshell-next-matching-input-from-input)
  39. (if eshell-hist-match-partial
  40. (progn
  41. (define-key eshell-mode-map [(meta ?p)]
  42. 'eshell-previous-matching-input-from-input)
  43. (define-key eshell-mode-map [(meta ?n)]
  44. 'eshell-next-matching-input-from-input)
  45. (define-key eshell-command-map [(meta ?p)] 'eshell-previous-input)
  46. (define-key eshell-command-map [(meta ?n)] 'eshell-next-input))
  47. (define-key eshell-mode-map [(meta ?p)] 'eshell-previous-input)
  48. (define-key eshell-mode-map [(meta ?n)] 'eshell-next-input)
  49. (define-key eshell-command-map [(meta ?p)]
  50. 'eshell-previous-matching-input-from-input)
  51. (define-key eshell-command-map [(meta ?n)]
  52. 'eshell-next-matching-input-from-input)))
  53. (make-local-variable 'eshell-history-size)
  54. (or eshell-history-size
  55. (let ((hsize (getenv "HISTSIZE")))
  56. (setq eshell-history-size
  57. (if (and (stringp hsize)
  58. (integerp (setq hsize (string-to-number hsize)))
  59. (> hsize 0))
  60. hsize
  61. 128))))
  62. (make-local-variable 'eshell-history-file-name)
  63. (or eshell-history-file-name
  64. (setq eshell-history-file-name (getenv "HISTFILE")))
  65. (make-local-variable 'eshell-history-index)
  66. (make-local-variable 'eshell-save-history-index)
  67. (if (minibuffer-window-active-p (selected-window))
  68. (set (make-local-variable 'eshell-save-history-on-exit) nil)
  69. (set (make-local-variable 'eshell-history-ring) nil)
  70. (if eshell-history-file-name
  71. (eshell-read-history nil t))
  72. (add-hook 'eshell-exit-hook 'eshell-write-history nil t))
  73. (unless eshell-history-ring
  74. (setq eshell-history-ring (make-ring eshell-history-size)))
  75. (add-hook 'eshell-exit-hook 'eshell-write-history nil t)
  76. (add-hook 'kill-emacs-hook 'eshell-save-some-history)
  77. (make-local-variable 'eshell-input-filter-functions)
  78. (add-hook 'eshell-input-filter-functions 'eshell-add-to-history nil t)
  79. (define-key eshell-command-map [(control ?l)] 'eshell-list-history)
  80. (define-key eshell-command-map [(control ?x)] 'eshell-get-next-from-history)))
  81. ;;; Fix 29854, expected in Emacs 26.1?
  82. (setq
  83. ansi-color-apply-face-function
  84. (lambda (beg end face)
  85. (when face
  86. (put-text-property beg end 'face face))))
  87. ;;; REVIEW: Ignore dups in the entire ring, not just the last entry.
  88. ;;; Reported upstream, see #30466.
  89. (defun eshell-add-input-to-history (input)
  90. "Add the string INPUT to the history ring.
  91. Input is entered into the input history ring, if the value of
  92. variable `eshell-input-filter' returns non-nil when called on the
  93. input."
  94. (when (funcall eshell-input-filter input)
  95. (when eshell-hist-ignoredups
  96. (ring-remove eshell-history-ring
  97. (ring-member eshell-history-ring input)))
  98. (eshell-put-history input))
  99. (setq eshell-save-history-index eshell-history-index)
  100. (setq eshell-history-index nil))
  101. (provide 'patch-eshell-26)