Created
September 26, 2022 16:16
-
-
Save cdegroot/701bf648575e0b7a63a92f7463bd2888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(eval-after-load "term" | |
'(defun term-handle-ansi-terminal-messages (message) | |
;; Is there a command here? | |
(while (string-match "\eAnSiT.+\n" message) | |
;; Extract the command code and the argument. | |
(let* ((start (match-beginning 0)) | |
(command-code (aref message (+ start 6))) | |
(argument | |
(save-match-data | |
(substring message | |
(+ start 8) | |
(string-match "\r?\n" message | |
(+ start 8))))) | |
ignore) | |
;; Delete this command from MESSAGE. | |
(setq message (replace-match "" t t message)) | |
;; If we recognize the type of command, set the appropriate variable. | |
(cond ((= command-code ?c) | |
(setq term-ansi-at-dir argument)) | |
((= command-code ?h) | |
(setq term-ansi-at-host argument)) | |
((= command-code ?u) | |
(setq term-ansi-at-user argument)) | |
;; Local stuff I added - CdG | |
((= command-code ?e) | |
(progn | |
(setq ignore t) | |
(save-excursion | |
(cdg/find-file-with-line argument t)))) | |
;; Otherwise ignore this one. | |
(t | |
(setq ignore t))) | |
;; Update default-directory based on the changes this command made. | |
(if ignore | |
nil | |
(setq default-directory | |
(file-name-as-directory | |
(if (and (string= term-ansi-at-host (system-name)) | |
(string= term-ansi-at-user (user-real-login-name))) | |
(expand-file-name term-ansi-at-dir) | |
(if (string= term-ansi-at-user (user-real-login-name)) | |
(concat "/" term-ansi-at-host ":" term-ansi-at-dir) | |
(concat "/" term-ansi-at-user "@" term-ansi-at-host ":" | |
term-ansi-at-dir))))) | |
;; I'm not sure this is necessary, | |
;; but it's best to be on the safe side. | |
(if (string= term-ansi-at-host (system-name)) | |
(progn | |
(setq ange-ftp-default-user term-ansi-at-save-user) | |
(setq ange-ftp-default-password term-ansi-at-save-pwd) | |
(setq ange-ftp-generate-anonymous-password term-ansi-at-save-anon)) | |
(setq term-ansi-at-save-user ange-ftp-default-user) | |
(setq term-ansi-at-save-pwd ange-ftp-default-password) | |
(setq term-ansi-at-save-anon ange-ftp-generate-anonymous-password) | |
(setq ange-ftp-default-user nil) | |
(setq ange-ftp-default-password nil) | |
(setq ange-ftp-generate-anonymous-password nil))))) | |
message)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment