commit fb9c52bb7d29c85f3baee770355260830dacea50 (HEAD, refs/remotes/origin/master) Author: Paul Eggert Date: Wed May 30 12:59:59 2018 -0700 Work around GCC bug 81401 * src/xterm.c (x_draw_glyphless_glyph_string_foreground): Make the buffer a byte longer than it needs to be, if --enable-gcc-warnings. diff --git a/src/xterm.c b/src/xterm.c index 4bdec7134f..eb299c3675 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -1973,7 +1973,13 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s) for (i = 0; i < s->nchars; i++, glyph++) { - char buf[7], *str = NULL; +#ifdef GCC_LINT + enum { PACIFY_GCC_BUG_81401 = 1 }; +#else + enum { PACIFY_GCC_BUG_81401 = 0 }; +#endif + char buf[7 + PACIFY_GCC_BUG_81401]; + char *str = NULL; int len = glyph->u.glyphless.len; if (glyph->u.glyphless.method == GLYPHLESS_DISPLAY_ACRONYM) commit adc20d64eb551349f628040c7d04f0edf1c76493 Author: Roland Winkler Date: Wed May 30 10:24:46 2018 -0500 bibtex-search-entry: Reuse the window displaying the buffer. * textmodes/bibtex.el (bibtex-reposition-window): New optional arg pos. (bibtex-search-crossref, bibtex-search-entry): Use it. (bibtex-search-entry): If possible, reuse the window displaying the buffer that contains the entry found. diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index dc19c3c0b9..50a30cf6c3 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -3850,11 +3850,13 @@ Return the new location of point." (re-search-forward "[\n\C-m]" nil 'end (1- arg)) (forward-line (1- arg)))) -(defun bibtex-reposition-window () +(defun bibtex-reposition-window (&optional pos) "Make the current BibTeX entry visible. If entry is smaller than `window-body-height', entry is centered in window. -Otherwise display the beginning of entry." +Otherwise display the beginning of entry. +Optional arg POS is the position of the BibTeX entry to use." (interactive) + (if pos (goto-char pos)) (let ((pnt (point)) (beg (line-number-at-pos (bibtex-beginning-of-entry))) (end (line-number-at-pos (bibtex-end-of-entry)))) @@ -4063,8 +4065,7 @@ for a crossref key, t otherwise." (message "Key `%s' is current entry" crossref-key) (if eqb (select-window (split-window)) (pop-to-buffer buffer)) - (goto-char pos) - (bibtex-reposition-window) + (bibtex-reposition-window pos) (beginning-of-line) (if (and eqb (> pnt pos) (not noerror)) (error "The referencing entry must precede the crossrefed entry!")))) @@ -4112,9 +4113,14 @@ A prefix arg negates the value of `bibtex-search-entry-globally'." (if (cdr (assoc-string key bibtex-reference-keys)) (setq found (bibtex-search-entry key))))) (cond ((and found display) - (switch-to-buffer buffer) - (goto-char found) - (bibtex-reposition-window)) + ;; If possible, reuse the window displaying BUFFER. + (let ((window (get-buffer-window buffer t))) + (if window + (progn + (select-frame-set-input-focus (window-frame window)) + (select-window window)) + (switch-to-buffer buffer))) + (bibtex-reposition-window found)) (found (set-buffer buffer)) (display (message "Key `%s' not found" key))) found) commit ec129c194725c5617a32037d2ab8b0df09bcac0f Author: Roland Winkler Date: Wed May 30 10:23:22 2018 -0500 bibtex-mark-entry: Display no message. * textmodes/bibtex.el (bibtex-mark-entry): Display no message. diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index 65d0675d0e..dc19c3c0b9 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -3873,9 +3873,10 @@ Otherwise display the beginning of entry." (goto-char pnt))))) (defun bibtex-mark-entry () - "Put mark at beginning, point at end of current BibTeX entry." + "Put mark at beginning, point at end of current BibTeX entry. +Activate mark in Transient Mark mode." (interactive) - (push-mark (bibtex-beginning-of-entry) :activate t) + (push-mark (bibtex-beginning-of-entry) t t) (bibtex-end-of-entry)) (defun bibtex-count-entries (&optional count-string-entries) commit 5c519cd95f573c380ef66243933348e69df6d3c5 Author: Roland Winkler Date: Wed May 30 10:21:57 2018 -0500 bibtex-format-entry: Preserve opt-alt if possible. * textmodes/bibtex.el (bibtex-format-entry): Preserve opt-alt unless its removal is selected. (bibtex-parse-entry): New optional arg keep-opt-alt. diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index 0111d48ba7..65d0675d0e 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -2345,7 +2345,8 @@ Formats current entry according to variable `bibtex-entry-format'." (when (memq 'sort-fields format) (goto-char (point-min)) (let ((beg-fields (save-excursion (bibtex-beginning-first-field))) - (fields-alist (bibtex-parse-entry)) + (fields-alist (bibtex-parse-entry + nil (not (memq 'opts-or-alts format)))) bibtex-help-message elt) (delete-region beg-fields (point)) (dolist (field default-field-list) @@ -2367,7 +2368,8 @@ Formats current entry according to variable `bibtex-entry-format'." (end-text (copy-marker (bibtex-end-of-text-in-field bounds) t)) (empty-field (equal "" (bibtex-text-in-field-bounds bounds t))) (field-name (buffer-substring-no-properties beg-name end-name)) - (opt-alt (and (string-match "\\`\\(OPT\\|ALT\\)" field-name) + (opt-alt (and (memq 'opts-or-alts format) + (string-match "\\`\\(OPT\\|ALT\\)" field-name) (not (and bibtex-no-opt-remove-re (string-match bibtex-no-opt-remove-re field-name))))) @@ -3641,20 +3643,20 @@ When called interactively with a prefix arg, query for a value of ENTRY-TYPE." (mapc 'bibtex-make-field required) (mapc 'bibtex-make-optional-field optional))))) -(defun bibtex-parse-entry (&optional content) +(defun bibtex-parse-entry (&optional content keep-opt-alt) "Parse entry at point, return an alist. The alist elements have the form (FIELD . TEXT), where FIELD can also be the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\" -TEXT may be nil. Remove \"OPT\" and \"ALT\" from FIELD. -Move point to the end of the last field. -If optional arg CONTENT is non-nil extract content of text fields." +TEXT may be nil. Move point to the end of the last field. +If optional arg CONTENT is non-nil extract content of text fields. +Remove \"OPT\" and \"ALT\" from FIELD unless KEEP-OPT-ALT is non-nil." (let (alist bounds) (when (looking-at bibtex-entry-maybe-empty-head) (push (cons "=type=" (bibtex-type-in-head)) alist) (push (cons "=key=" (bibtex-key-in-head)) alist) (goto-char (match-end 0)) (while (setq bounds (bibtex-parse-field)) - (push (cons (bibtex-name-in-field bounds t) + (push (cons (bibtex-name-in-field bounds (not keep-opt-alt)) (bibtex-text-in-field-bounds bounds content)) alist) (goto-char (bibtex-end-of-field bounds)))) commit 58d0642e1ca006fa550bff50fd328bc166c572da Author: Simen Heggestøyl Date: Tue May 29 19:14:34 2018 +0200 Add Imenu support to CSS mode and its derivatives * lisp/textmodes/css-mode.el (css--join-nested-selectors) (css--prev-index-position, css--extract-index-name): New helper functions for supporting Imenu. (css-mode): Set `imenu-space-replacement', `imenu-prev-index-position-function', and `imenu-extract-index-name-function'. (css-current-defun-name): Reuse `css--prev-index-position' and `css--extract-index-name' to support nested selectors. * test/lisp/textmodes/css-mode-tests.el (css-test-current-defun-name): Fix character index. (css-test-join-nested-selectors): New tests for `css--join-nested-selectors'. * etc/NEWS: Add news entry. diff --git a/etc/NEWS b/etc/NEWS index ea4a657cba..bd25f43ad0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -263,6 +263,9 @@ Can be controlled via the new variable 'footnote-align-to-fn-text'. formats (e.g. "black" => "#000000" => "rgb(0, 0, 0)") has been added, bound to 'C-c C-f'. +--- +*** CSS mode, SCSS mode, and Less CSS mode now have support for Imenu. + ** SGML mode --- diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 727bc18ebb..6d06dddadc 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -35,6 +35,7 @@ (require 'cl-lib) (require 'color) (require 'eww) +(require 'imenu) (require 'seq) (require 'sgml-mode) (require 'smie) @@ -1516,6 +1517,55 @@ rgb()/rgba()." (css--rgb-to-named-color-or-hex) (message "It doesn't look like a color at point"))) +(defun css--join-nested-selectors (selectors) + "Join a list of nested CSS selectors." + (let ((processed '()) + (prev nil)) + (dolist (sel selectors) + (cond + ((seq-contains sel ?&) + (setq sel (replace-regexp-in-string "&" prev sel)) + (pop processed)) + ;; Unless this is the first selector, separate this one and the + ;; previous one by a space. + (processed + (push " " processed))) + (push sel processed) + (setq prev sel)) + (apply #'concat (nreverse processed)))) + +(defun css--prev-index-position () + (when (nth 7 (syntax-ppss)) + (goto-char (comment-beginning))) + (forward-comment (- (point))) + (when (search-backward "{" (point-min) t) + (if (re-search-backward "}\\|;\\|{" (point-min) t) + (forward-char) + (goto-char (point-min))) + (forward-comment (point-max)) + (save-excursion (re-search-forward "[^{;]*")))) + +(defun css--extract-index-name () + (save-excursion + (let ((res (list (match-string-no-properties 0)))) + (condition-case nil + (while t + (goto-char (nth 1 (syntax-ppss))) + (if (re-search-backward "}\\|;\\|{" (point-min) t) + (forward-char) + (goto-char (point-min))) + (forward-comment (point-max)) + (when (save-excursion + (re-search-forward "[^{;]*")) + (push (match-string-no-properties 0) res))) + (error + (css--join-nested-selectors + (mapcar + (lambda (s) + (string-trim + (replace-regexp-in-string "[\n ]+" " " s))) + res))))))) + ;;;###autoload (define-derived-mode css-mode prog-mode "CSS" "Major mode to edit Cascading Style Sheets (CSS). @@ -1551,7 +1601,13 @@ Network (MDN). (append css-electric-keys electric-indent-chars)) (setq-local font-lock-fontify-region-function #'css--fontify-region) (add-hook 'completion-at-point-functions - #'css-completion-at-point nil 'local)) + #'css-completion-at-point nil 'local) + ;; The default "." creates ambiguity with class selectors. + (setq-local imenu-space-replacement " ") + (setq-local imenu-prev-index-position-function + #'css--prev-index-position) + (setq-local imenu-extract-index-name-function + #'css--extract-index-name)) (defvar comment-continue) @@ -1648,12 +1704,8 @@ Network (MDN). (defun css-current-defun-name () "Return the name of the CSS section at point, or nil." (save-excursion - (let ((max (max (point-min) (- (point) 1600)))) ; approx 20 lines back - (when (search-backward "{" max t) - (skip-chars-backward " \t\r\n") - (beginning-of-line) - (if (looking-at "^[ \t]*\\([^{\r\n]*[^ {\t\r\n]\\)") - (match-string-no-properties 1)))))) + (when (css--prev-index-position) + (css--extract-index-name)))) ;;; SCSS mode diff --git a/test/lisp/textmodes/css-mode-tests.el b/test/lisp/textmodes/css-mode-tests.el index b0283bfa45..bfae1bf2f7 100644 --- a/test/lisp/textmodes/css-mode-tests.el +++ b/test/lisp/textmodes/css-mode-tests.el @@ -85,7 +85,7 @@ (insert "body { top: 0; }") (goto-char 7) (should (equal (css-current-defun-name) "body")) - (goto-char 18) + (goto-char 15) (should (equal (css-current-defun-name) "body")))) (ert-deftest css-test-current-defun-name-nested () @@ -324,6 +324,19 @@ (css-cycle-color-format) (should (equal (buffer-string) "black")))) +(ert-deftest css-test-join-nested-selectors () + (should (equal (css--join-nested-selectors '("div" "&:hover")) + "div:hover")) + (should + (equal (css--join-nested-selectors '("a" "&::before, &::after")) + "a::before, a::after")) + (should + (equal (css--join-nested-selectors + '("article" "& > .front-page" "& h1, & h2")) + "article > .front-page h1, article > .front-page h2")) + (should (equal (css--join-nested-selectors '(".link" "& + &")) + ".link + .link"))) + (ert-deftest css-mdn-symbol-guessing () (dolist (item '(("@med" "ia" "@media") ("@keyframes " "{" "@keyframes") commit 5be83e343f9f0f3487793b54ff95bc89ee6b824a Author: Eli Zaretskii Date: Tue May 29 20:52:17 2018 +0300 Allow access to MS-Windows Registry from Lisp programs * src/w32.c (g_b_init_reg_open_key_ex_w) (g_b_init_reg_query_value_ex_w) (g_b_init_expand_environment_strings_w): New init flags. (globals_of_w32): Initialize them at startup. (RegOpenKeyExW_Proc, RegQueryValueExW_Proc) (ExpandEnvironmentStringsW_Proc): New function typedefs. (reg_open_key_ex_w, reg_query_value_ex_w) (expand_environment_strings_w): New wrapper function. (w32_read_registry): New function. * src/w32fns.c (Fw32_read_registry) [WINDOWSNT]: New primitive. (syms_of_w32fns) [WINDOWSNT]: Defsubr it. DEFSYM "HKLM", "HKCU", etc. root keys. * etc/NEWS: Mention the new primitive. diff --git a/etc/NEWS b/etc/NEWS index 5ac803eec4..ea4a657cba 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -682,6 +682,13 @@ to 't' would enable the macOS proxy icon has been replaced with a separate variable, 'ns-use-proxy-icon'. 'frame-title-format' will now work as on other platforms. +--- +** New primitive 'w32-read-registry'. +This primitive lets Lisp programs access the MS-Windows Registry by +retrieving values stored under a given key. It is intended to be used +for supporting features such as XDG-like location of important files +and directories. + ---------------------------------------------------------------------- This file is part of GNU Emacs. diff --git a/src/w32.c b/src/w32.c index 5ac6618140..e93aaab9ca 100644 --- a/src/w32.c +++ b/src/w32.c @@ -326,6 +326,9 @@ static BOOL g_b_init_set_file_security_a; static BOOL g_b_init_set_named_security_info_w; static BOOL g_b_init_set_named_security_info_a; static BOOL g_b_init_get_adapters_info; +static BOOL g_b_init_reg_open_key_ex_w; +static BOOL g_b_init_reg_query_value_ex_w; +static BOOL g_b_init_expand_environment_strings_w; BOOL g_b_init_compare_string_w; BOOL g_b_init_debug_break_process; @@ -504,6 +507,9 @@ typedef DWORD (WINAPI *GetAdaptersInfo_Proc) ( int (WINAPI *pMultiByteToWideChar)(UINT,DWORD,LPCSTR,int,LPWSTR,int); int (WINAPI *pWideCharToMultiByte)(UINT,DWORD,LPCWSTR,int,LPSTR,int,LPCSTR,LPBOOL); DWORD multiByteToWideCharFlags; +typedef LONG (WINAPI *RegOpenKeyExW_Proc) (HKEY,LPCWSTR,DWORD,REGSAM,PHKEY); +typedef LONG (WINAPI *RegQueryValueExW_Proc) (HKEY,LPCWSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD); +typedef DWORD (WINAPI *ExpandEnvironmentStringsW_Proc) (LPCWSTR,LPWSTR,DWORD); /* ** A utility function ** */ static BOOL @@ -1376,6 +1382,79 @@ get_adapters_info (PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen) return s_pfn_Get_Adapters_Info (pAdapterInfo, pOutBufLen); } +static LONG WINAPI +reg_open_key_ex_w (HKEY hkey, LPCWSTR lpSubKey, DWORD ulOptions, + REGSAM samDesired, PHKEY phkResult) +{ + static RegOpenKeyExW_Proc s_pfn_Reg_Open_Key_Ex_w = NULL; + HMODULE hm_advapi32 = NULL; + + if (is_windows_9x () == TRUE) + return ERROR_NOT_SUPPORTED; + + if (g_b_init_reg_open_key_ex_w == 0) + { + g_b_init_reg_open_key_ex_w = 1; + hm_advapi32 = LoadLibrary ("Advapi32.dll"); + if (hm_advapi32) + s_pfn_Reg_Open_Key_Ex_w = (RegOpenKeyExW_Proc) + GetProcAddress (hm_advapi32, "RegOpenKeyExW"); + } + if (s_pfn_Reg_Open_Key_Ex_w == NULL) + return ERROR_NOT_SUPPORTED; + return s_pfn_Reg_Open_Key_Ex_w (hkey, lpSubKey, ulOptions, + samDesired, phkResult); +} + +static LONG WINAPI +reg_query_value_ex_w (HKEY hkey, LPCWSTR lpValueName, LPDWORD lpReserved, + LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) +{ + static RegQueryValueExW_Proc s_pfn_Reg_Query_Value_Ex_w = NULL; + HMODULE hm_advapi32 = NULL; + + if (is_windows_9x () == TRUE) + return ERROR_NOT_SUPPORTED; + + if (g_b_init_reg_query_value_ex_w == 0) + { + g_b_init_reg_query_value_ex_w = 1; + hm_advapi32 = LoadLibrary ("Advapi32.dll"); + if (hm_advapi32) + s_pfn_Reg_Query_Value_Ex_w = (RegQueryValueExW_Proc) + GetProcAddress (hm_advapi32, "RegQueryValueExW"); + } + if (s_pfn_Reg_Query_Value_Ex_w == NULL) + return ERROR_NOT_SUPPORTED; + return s_pfn_Reg_Query_Value_Ex_w (hkey, lpValueName, lpReserved, + lpType, lpData, lpcbData); +} + +static DWORD WINAPI +expand_environment_strings_w (LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize) +{ + static ExpandEnvironmentStringsW_Proc s_pfn_Expand_Environment_Strings_w = NULL; + HMODULE hm_kernel32 = NULL; + + if (is_windows_9x () == TRUE) + return ERROR_NOT_SUPPORTED; + + if (g_b_init_expand_environment_strings_w == 0) + { + g_b_init_expand_environment_strings_w = 1; + hm_kernel32 = LoadLibrary ("Kernel32.dll"); + if (hm_kernel32) + s_pfn_Expand_Environment_Strings_w = (ExpandEnvironmentStringsW_Proc) + GetProcAddress (hm_kernel32, "ExpandEnvironmentStringsW"); + } + if (s_pfn_Expand_Environment_Strings_w == NULL) + { + errno = ENOSYS; + return FALSE; + } + return s_pfn_Expand_Environment_Strings_w (lpSrc, lpDst, nSize); +} + /* Return 1 if P is a valid pointer to an object of size SIZE. Return @@ -9269,6 +9348,215 @@ network_interface_info (Lisp_Object ifname) } +/* Workhorse for w32-read-registry, which see. */ +Lisp_Object +w32_read_registry (HKEY rootkey, Lisp_Object lkey, Lisp_Object lname) +{ + HKEY hkey = NULL; + LONG status; + DWORD vsize, vtype; + LPBYTE pvalue; + Lisp_Object val, retval; + const char *key, *value_name; + /* The following sizes are according to size limitations + documented in MSDN. */ + wchar_t key_w[255+1]; + wchar_t value_w[16*1024+1]; + bool use_unicode = is_windows_9x () == 0; + + if (use_unicode) + { + Lisp_Object encoded_key, encoded_vname; + + /* Convert input strings to UTF-16. */ + encoded_key = code_convert_string_norecord (lkey, Qutf_16le, 1); + memcpy (key_w, SSDATA (encoded_key), SBYTES (encoded_key)); + /* wchar_t strings need to be terminated by 2 null bytes. */ + key_w [SBYTES (encoded_key)/2] = L'\0'; + encoded_vname = code_convert_string_norecord (lname, Qutf_16le, 1); + memcpy (value_w, SSDATA (encoded_vname), SBYTES (encoded_vname)); + value_w[SBYTES (encoded_vname)/2] = L'\0'; + + /* Mirror the slashes, if required. */ + for (int i = 0; i < SBYTES (encoded_key)/2; i++) + { + if (key_w[i] == L'/') + key_w[i] = L'\\'; + } + if ((status = reg_open_key_ex_w (rootkey, key_w, 0, + KEY_READ, &hkey)) == ERROR_NOT_SUPPORTED + || (status = reg_query_value_ex_w (hkey, value_w, NULL, NULL, NULL, + &vsize)) == ERROR_NOT_SUPPORTED + || status != ERROR_SUCCESS) + { + if (hkey) + RegCloseKey (hkey); + if (status != ERROR_NOT_SUPPORTED) + return Qnil; + use_unicode = 0; /* fall back to non-Unicode calls */ + } + } + if (!use_unicode) + { + /* Need to copy LKEY because we are going to modify it. */ + Lisp_Object local_lkey = Fcopy_sequence (lkey); + + /* Mirror the slashes. Note: this has to be done before + encoding, because after encoding we cannot guarantee that a + slash '/' always stands for itself, it could be part of some + multibyte sequence. */ + for (int i = 0; i < SBYTES (local_lkey); i++) + { + if (SSDATA (local_lkey)[i] == '/') + SSDATA (local_lkey)[i] = '\\'; + } + + key = SSDATA (ENCODE_SYSTEM (local_lkey)); + value_name = SSDATA (ENCODE_SYSTEM (lname)); + + if ((status = RegOpenKeyEx (rootkey, key, 0, + KEY_READ, &hkey)) != ERROR_SUCCESS + || (status = RegQueryValueEx (hkey, value_name, NULL, + NULL, NULL, &vsize)) != ERROR_SUCCESS) + { + if (hkey) + RegCloseKey (hkey); + return Qnil; + } + } + + pvalue = xzalloc (vsize); + if (use_unicode) + status = reg_query_value_ex_w (hkey, value_w, NULL, &vtype, pvalue, &vsize); + else + status = RegQueryValueEx (hkey, value_name, NULL, &vtype, pvalue, &vsize); + if (status != ERROR_SUCCESS) + { + xfree (pvalue); + RegCloseKey (hkey); + return Qnil; + } + + switch (vtype) + { + case REG_NONE: + retval = Qt; + break; + case REG_DWORD: + retval = INTEGER_TO_CONS (*((DWORD *)pvalue)); + break; + case REG_QWORD: + retval = INTEGER_TO_CONS (*((long long *)pvalue)); + break; + case REG_BINARY: + { + int i; + unsigned char *dbuf = (unsigned char *)pvalue; + + val = make_uninit_vector (vsize); + for (i = 0; i < vsize; i++) + ASET (val, i, make_number (dbuf[i])); + + retval = val; + break; + } + case REG_SZ: + if (use_unicode) + { + /* pvalue ends with 2 null bytes, but we need only one, + and AUTO_STRING_WITH_LEN will add it. */ + if (pvalue[vsize - 1] == '\0') + vsize -= 2; + AUTO_STRING_WITH_LEN (sval, (char *)pvalue, vsize); + retval = from_unicode (sval); + } + else + { + /* Don't waste a byte on the terminating null character, + since make_unibyte_string will add one anyway. */ + if (pvalue[vsize - 1] == '\0') + vsize--; + retval = DECODE_SYSTEM (make_unibyte_string (pvalue, vsize)); + } + break; + case REG_EXPAND_SZ: + if (use_unicode) + { + wchar_t expanded_w[32*1024]; + DWORD dsize = sizeof (expanded_w) / 2; + DWORD produced = expand_environment_strings_w ((wchar_t *)pvalue, + expanded_w, + dsize); + if (produced > 0 && produced < dsize) + { + AUTO_STRING_WITH_LEN (sval, (char *)expanded_w, + produced * 2 - 2); + retval = from_unicode (sval); + } + else + { + if (pvalue[vsize - 1] == '\0') + vsize -= 2; + AUTO_STRING_WITH_LEN (sval, (char *)pvalue, vsize); + retval = from_unicode (sval); + } + } + else + { + char expanded[32*1024]; /* size limitation according to MSDN */ + DWORD produced = ExpandEnvironmentStrings ((char *)pvalue, + expanded, + sizeof (expanded)); + if (produced > 0 && produced < sizeof (expanded)) + retval = make_unibyte_string (expanded, produced - 1); + else + { + if (pvalue[vsize - 1] == '\0') + vsize--; + retval = make_unibyte_string (pvalue, vsize); + } + + retval = DECODE_SYSTEM (retval); + } + break; + case REG_MULTI_SZ: + if (use_unicode) + { + wchar_t *wp = (wchar_t *)pvalue; + + val = Qnil; + do { + size_t wslen = wcslen (wp); + AUTO_STRING_WITH_LEN (sval, (char *)wp, wslen * 2); + val = Fcons (from_unicode (sval), val); + wp += wslen + 1; + } while (*wp); + } + else + { + char *p = (char *)pvalue; + + val = Qnil; + do { + size_t slen = strlen (p); + + val = Fcons (DECODE_SYSTEM (make_unibyte_string (p, slen)), val); + p += slen + 1; + } while (*p); + } + + retval = Fnreverse (val); + break; + default: + error ("unsupported registry data type: %d", (int)vtype); + } + + xfree (pvalue); + RegCloseKey (hkey); + return retval; +} + + /* The Windows CRT functions are "optimized for speed", so they don't check for timezone and DST changes if they were last called less than 1 minute ago (see http://support.microsoft.com/kb/821231). So @@ -9699,6 +9987,9 @@ globals_of_w32 (void) g_b_init_set_named_security_info_w = 0; g_b_init_set_named_security_info_a = 0; g_b_init_get_adapters_info = 0; + g_b_init_reg_open_key_ex_w = 0; + g_b_init_reg_query_value_ex_w = 0; + g_b_init_expand_environment_strings_w = 0; g_b_init_compare_string_w = 0; g_b_init_debug_break_process = 0; num_of_processors = 0; diff --git a/src/w32.h b/src/w32.h index 1e416ceead..fe8689a07b 100644 --- a/src/w32.h +++ b/src/w32.h @@ -227,6 +227,8 @@ extern int w32_compare_strings (const char *, const char *, char *, int); /* Return a cryptographically secure seed for PRNG. */ extern int w32_init_random (void *, ptrdiff_t); +extern Lisp_Object w32_read_registry (HKEY, Lisp_Object, Lisp_Object); + #ifdef HAVE_GNUTLS #include diff --git a/src/w32fns.c b/src/w32fns.c index 2b920f29c6..5d1c3c84c6 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -10059,6 +10059,78 @@ DEFUN ("w32-notification-close", #endif /* WINDOWSNT && !HAVE_DBUS */ +#ifdef WINDOWSNT +/*********************************************************************** + Reading Registry + ***********************************************************************/ +DEFUN ("w32-read-registry", + Fw32_read_registry, Sw32_read_registry, + 3, 3, 0, + doc: /* Return the value stored in MS-Windows Registry under ROOT/KEY/NAME. + +ROOT is a symbol, one of `HKCR', `HKCU', `HKLM', `HKU', or `HKCC'. +It can also be nil, which means try `HKCU', and if that fails, try `HKLM'. + +KEY and NAME must be strings, and NAME must not include slashes. +KEY can use either forward- or back-slashes. + +If the the named KEY or its subkey called NAME don't exist, or cannot +be accessed by the current user, the function returns nil. Otherwise, +the return value depends on the type of the data stored in Registry: + + If the data type is REG_NONE, the function returns t. + If the data type is REG_DWORD or REG_QWORD, the function returns + its integer value. If the value is too large for a Lisp integer, + the function returns a cons (HIGH . LOW) of 2 integers, with LOW + the low 16 bits and HIGH the high bits. If HIGH is too large for + a Lisp integer, the function returns (HIGH MIDDLE . LOW), first + the high bits, then the middle 24 bits, and finally the low 16 bits. + If the data type is REG_BINARY, the function returns a vector whose + elements are individual bytes of the value. + If the data type is REG_SZ, the function returns a string. + If the data type REG_EXPAND_SZ, the function returns a string with + all the %..% references to environment variables replaced by the + values of those variables. If the expansion fails, or some + variables are not defined in the environment, some or all of + the environment variables will remain unexpanded. + If the data type is REG_MULTI_SZ, the function returns a list whose + elements are the individual strings. + +Note that this function doesn't know whether a string value is a file +name, so file names will be returned with backslashes, which may need +to be converted to forward slashes by the caller. */) + (Lisp_Object root, Lisp_Object key, Lisp_Object name) +{ + CHECK_SYMBOL (root); + CHECK_STRING (key); + CHECK_STRING (name); + + HKEY rootkey; + if (EQ (root, QHKCR)) + rootkey = HKEY_CLASSES_ROOT; + else if (EQ (root, QHKCU)) + rootkey = HKEY_CURRENT_USER; + else if (EQ (root, QHKLM)) + rootkey = HKEY_LOCAL_MACHINE; + else if (EQ (root, QHKU)) + rootkey = HKEY_USERS; + else if (EQ (root, QHKCC)) + rootkey = HKEY_CURRENT_CONFIG; + else if (!NILP (root)) + error ("unknown root key: %s", SDATA (SYMBOL_NAME (root))); + + Lisp_Object val = w32_read_registry (NILP (root) + ? HKEY_CURRENT_USER + : rootkey, + key, name); + if (NILP (val) && NILP (root)) + val = w32_read_registry (HKEY_LOCAL_MACHINE, key, name); + + return val; +} + +#endif /* WINDOWSNT */ + /*********************************************************************** Initialization ***********************************************************************/ @@ -10151,6 +10223,14 @@ syms_of_w32fns (void) DEFSYM (QCbody, ":body"); #endif +#ifdef WINDOWSNT + DEFSYM (QHKCR, "HKCR"); + DEFSYM (QHKCU, "HKCU"); + DEFSYM (QHKLM, "HKLM"); + DEFSYM (QHKU, "HKU"); + DEFSYM (QHKCC, "HKCC"); +#endif + /* Symbols used elsewhere, but only in MS-Windows-specific code. */ DEFSYM (Qgnutls, "gnutls"); DEFSYM (Qlibxml2, "libxml2"); @@ -10508,6 +10588,7 @@ tip frame. */); #endif #ifdef WINDOWSNT + defsubr (&Sw32_read_registry); defsubr (&Sfile_system_info); defsubr (&Sdefault_printer_name); #endif commit fd6f08840eb095465dfe555785eee228306ab876 Author: Michael Albinus Date: Tue May 29 12:55:04 2018 +0200 * doc/misc/tramp.texi (All): Use @code instead of @option for user options. diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index c34341b9ac..38669a06c9 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -3500,7 +3500,7 @@ first saving to a temporary file. When connecting to a local host, @value{tramp} uses some internal optimizations. They fail, when there is a chrooted environment. In order to disable those optimizations, set user option -@option{tramp-local-host-regexp} to @code{nil}. +@code{tramp-local-host-regexp} to @code{nil}. @item commit e5b98e02731556f891003d10ab6fc76e6b1c3dcb Merge: b3207538c6 13963a3a5c Author: Michael Albinus Date: Tue May 29 12:45:47 2018 +0200 Merge from origin/emacs-26 13963a3a5c * doc/misc/tramp.texi (All): Use @code instead of @option ... 6e5f19ada4 Fix Bug#31605 commit 13963a3a5c83aff1eacee933361e3ac0f21828cd Author: Michael Albinus Date: Tue May 29 12:42:17 2018 +0200 * doc/misc/tramp.texi (All): Use @code instead of @option for user options. diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 2960368447..4e75b9a8f0 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -671,7 +671,7 @@ remote host, and then tries that program for encoding and decoding. @vindex tramp-inline-compress-start-size To increase transfer speeds for large text files, use compression before encoding. The user option -@option{tramp-inline-compress-start-size} specifies the file size for +@code{tramp-inline-compress-start-size} specifies the file size for such optimization. @table @asis @@ -1027,11 +1027,11 @@ devices. The Android Debug Bridge must be installed locally for Debug Bridge as an installation package. Alternatively, the program is installed as part of the Android SDK@. @value{tramp} finds the @command{adb} program either via the @env{PATH} environment variable -or the absolute path set in the user option @option{tramp-adb-program}. +or the absolute path set in the user option @code{tramp-adb-program}. @vindex tramp-adb-connect-if-not-connected @value{tramp} connects to Android devices with @option{adb} only when -the user option @option{tramp-adb-connect-if-not-connected} is not +the user option @code{tramp-adb-connect-if-not-connected} is not @code{nil}. Otherwise, the connection must be established outside Emacs. @@ -1149,7 +1149,7 @@ pseudo method @option{-}, @ref{File name syntax}. @defopt tramp-default-method Default method is for transferring files. The user option -@option{tramp-default-method} sets it. @value{tramp} uses this user +@code{tramp-default-method} sets it. @value{tramp} uses this user option to determine the default method for remote file names that do not have one specified. @@ -1161,7 +1161,7 @@ not have one specified. @defopt tramp-default-method-alist Default methods for transferring files can be customized for specific user and host combinations through the user option -@option{tramp-default-method-alist}. +@code{tramp-default-method-alist}. For example, the following two lines specify to use the @option{ssh} method for all user names matching @samp{john} and the @option{rsync} @@ -1237,7 +1237,7 @@ improvement is not always true. @defopt tramp-default-user @value{tramp} file name can omit the user name part since @value{tramp} substitutes the currently logged-in user name. However -this substitution can be overridden with @option{tramp-default-user}. +this substitution can be overridden with @code{tramp-default-user}. For example: @lisp @@ -1246,7 +1246,7 @@ For example: @end defopt @defopt tramp-default-user-alist -Instead of a single default user, @option{tramp-default-user-alist} +Instead of a single default user, @code{tramp-default-user-alist} allows multiple default user values based on access method or host name combinations. The alist can hold multiple values. For example, to use the @samp{john} as the default user for the domain @@ -1271,7 +1271,7 @@ corresponding alist entry to nil: @end group @end lisp -The last entry in @option{tramp-default-user-alist} should be reserved +The last entry in @code{tramp-default-user-alist} should be reserved for catch-all or most often used login. @lisp @@ -1289,7 +1289,7 @@ for catch-all or most often used login. @defopt tramp-default-host When host name is omitted, @value{tramp} substitutes the value from -the @option{tramp-default-host} user option. It is initially +the @code{tramp-default-host} user option. It is initially populated with the local host name where Emacs is running. The default method, default user and default host can be overridden as follows: @@ -1308,10 +1308,10 @@ to John's home directory on @code{target} via @code{ssh}. @end defopt @defopt tramp-default-host-alist -Instead of a single default host, @option{tramp-default-host-alist} +Instead of a single default host, @code{tramp-default-host-alist} allows multiple default host values based on access method or user name combinations. The alist can hold multiple values. While -@option{tramp-default-host} is sufficient in most cases, some methods, +@code{tramp-default-host} is sufficient in most cases, some methods, like @option{adb}, require defaults overwritten. @end defopt @@ -1329,7 +1329,7 @@ hop kind, where the start and end points of the connection did not have intermediate check points. @defopt tramp-default-proxies-alist -@option{tramp-default-proxies-alist} specifies proxy hosts to pass +@code{tramp-default-proxies-alist} specifies proxy hosts to pass through. This user option is list of triples consisting of @code{(@var{host} @var{user} @var{proxy})}. @@ -1683,16 +1683,16 @@ Set @code{password-cache} to @code{nil} to disable password caching. @vindex tramp-persistency-file-name For faster initial connection times, @value{tramp} stores previous connection properties in a file specified by the user option -@option{tramp-persistency-file-name}. +@code{tramp-persistency-file-name}. -The default file name for @option{tramp-persistency-file-name} is +The default file name for @code{tramp-persistency-file-name} is @file{~/.emacs.d/tramp}. @value{tramp} reads this file during Emacs startup, and writes to it when exiting Emacs. Delete this file for @value{tramp} to recreate a new one on next Emacs startup. -Set @option{tramp-persistency-file-name} to @code{nil} to disable +Set @code{tramp-persistency-file-name} to @code{nil} to disable storing connections persistently. When @value{tramp} detects a change in the operating system version in @@ -1707,7 +1707,7 @@ For more precise customization, parameters specified by @code{tramp-methods} can be overwritten manually. @vindex tramp-connection-properties -Set @option{tramp-connection-properties} to manually override +Set @code{tramp-connection-properties} to manually override @code{tramp-methods}. Properties in this list are in the form @code{(@var{regexp} @var{property} @var{value})}. @var{regexp} matches remote file names. Use @code{nil} to match all. @@ -1739,7 +1739,7 @@ The parameters @code{tramp-remote-shell} and values for the remote host. @var{property} could also be any property found in -@option{tramp-persistency-file-name}. +@code{tramp-persistency-file-name}. To get around how restricted shells randomly drop connections, set the special property @samp{busybox}. For example: @@ -1768,7 +1768,7 @@ To improve performance and accuracy of remote file access, @command{grep} when available. @defopt tramp-remote-path -@option{tramp-remote-path} specifies which remote directory paths +@code{tramp-remote-path} specifies which remote directory paths @value{tramp} can search for @ref{Remote programs}. @vindex tramp-default-remote-path @@ -1793,7 +1793,7 @@ Another way to find the remote path is to use the path assigned to the remote user by the remote host. @value{tramp} does not normally retain this remote path after login. However, @code{tramp-own-remote-path} preserves the path value, which can be used to update -@option{tramp-remote-path}. +@code{tramp-remote-path}. @lisp (add-to-list 'tramp-remote-path 'tramp-own-remote-path) @@ -1837,22 +1837,22 @@ login security, especially not the exotic ones. However, @value{tramp} provides a few tweaks to address the most common ones. @table @asis -@item @option{tramp-shell-prompt-pattern} +@item @code{tramp-shell-prompt-pattern} @vindex tramp-shell-prompt-pattern -@option{tramp-shell-prompt-pattern} is for remote login shell prompt, +@code{tramp-shell-prompt-pattern} is for remote login shell prompt, which may not be the same as the local login shell prompt, @code{shell-prompt-pattern}. Since most hosts use identical prompts, @value{tramp} sets a similar default value for both prompts. -@item @option{tramp-password-prompt-regexp} -@item @option{tramp-wrong-passwd-regexp} +@item @code{tramp-password-prompt-regexp} +@item @code{tramp-wrong-passwd-regexp} @vindex tramp-password-prompt-regexp @vindex tramp-wrong-passwd-regexp -@value{tramp} uses @option{tramp-password-prompt-regexp} to +@value{tramp} uses @code{tramp-password-prompt-regexp} to distinguish between prompts for passwords and prompts for passphrases. -By default, @option{tramp-password-prompt-regexp} handles the +By default, @code{tramp-password-prompt-regexp} handles the detection in English language environments. See a localization example below: @@ -1876,7 +1876,7 @@ example below: @end lisp Similar localization may be necessary for handling wrong password -prompts, for which @value{tramp} uses @option{tramp-wrong-passwd-regexp}. +prompts, for which @value{tramp} uses @code{tramp-wrong-passwd-regexp}. @item @code{tramp-terminal-type} @vindex tramp-terminal-type @@ -1934,7 +1934,7 @@ echo $INSIDE_EMACS To suppress inappropriate prompts for terminal type, @value{tramp} sets the @env{TERM} environment variable before the remote login -process begins via the user option @option{tramp-terminal-type} (see +process begins via the user option @code{tramp-terminal-type} (see above). This will silence common @command{tset} related prompts. @value{tramp}'s strategy for handling such prompts (commonly triggered @@ -2168,7 +2168,7 @@ Open a remote connection with a more concise command @kbd{C-x C-f @vindex backup-directory-alist To avoid @value{tramp} from saving backup files owned by @samp{root} to locations accessible to others, default backup settings in -@option{backup-directory-alist} have to be altered. +@code{backup-directory-alist} have to be altered. Here's a scenario where files could be inadvertently exposed. Emacs by default writes backup files to the same directory as the original @@ -2179,7 +2179,7 @@ default by @value{tramp} when using, say, a restricted file of the secretfile is now owned by the user logged in from @value{tramp} and not @samp{root}. -When @option{backup-directory-alist} is @code{nil} (the default), such +When @code{backup-directory-alist} is @code{nil} (the default), such problems do not occur. To ``turn off'' the backup feature for @value{tramp} files and stop @@ -2213,8 +2213,8 @@ Another option is to create better backup file naming with user and host names prefixed to the file name. For example, transforming @file{/etc/secretfile} to @file{~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile}, set the -@value{tramp} user option @option{tramp-backup-directory-alist} from -the existing user option @option{backup-directory-alist}. +@value{tramp} user option @code{tramp-backup-directory-alist} from +the existing user option @code{backup-directory-alist}. Then @value{tramp} backs up to a file name that is transformed with a prefix consisting of the DIRECTORY name. This file name prefixing @@ -2246,16 +2246,16 @@ The backup file name of Just as for backup files, similar issues of file naming affect auto-saving @value{tramp} files. Auto-saved files are saved in the directory specified by the user option -@option{auto-save-file-name-transforms}. By default this is set to +@code{auto-save-file-name-transforms}. By default this is set to the local temporary directory. But in some versions of Debian GNU/Linux, this points to the source directory where the Emacs was compiled. Reset such values to a valid directory. -Set @option{auto-save-file-name-transforms} to @code{nil} to save +Set @code{auto-save-file-name-transforms} to @code{nil} to save auto-saved files to the same directory as the original file. @vindex tramp-auto-save-directory -Alternatively, set the user option @option{tramp-auto-save-directory} +Alternatively, set the user option @code{tramp-auto-save-directory} to direct all auto saves to that location. @node Windows setup hints @@ -2577,7 +2577,7 @@ directory contents. @cindex proxy hosts, ad-hoc @value{tramp} file name syntax can accommodate ad hoc specification of -multiple proxies without using @option{tramp-default-proxies-alist} +multiple proxies without using @code{tramp-default-proxies-alist} configuration setup(@pxref{Multi-hops}). Each proxy is specified using the same syntax as the remote host @@ -2594,15 +2594,15 @@ proxy @samp{bird@@bastion} to a remote file on @samp{you@@remotehost}: Proxies can take patterns @code{%h} or @code{%u}. @value{tramp} adds the ad-hoc definitions on the fly to -@option{tramp-default-proxies-alist} and is available for re-use +@code{tramp-default-proxies-alist} and is available for re-use during that Emacs session. Subsequent @value{tramp} connections to the same remote host can then use the shortcut form: @samp{@trampfn{ssh,you@@remotehost,/path}}. @defopt tramp-save-ad-hoc-proxies For ad-hoc definitions to be saved automatically in -@option{tramp-default-proxies-alist} for future Emacs sessions, set -@option{tramp-save-ad-hoc-proxies} to non-@code{nil}. +@code{tramp-default-proxies-alist} for future Emacs sessions, set +@code{tramp-save-ad-hoc-proxies} to non-@code{nil}. @lisp (customize-set-variable 'tramp-save-ad-hoc-proxies t) @@ -2647,7 +2647,7 @@ like @code{compile} and @code{grep}) and @file{gud.el} (@code{gdb} or For @value{tramp} to find the command on the remote, it must be accessible through the default search path as setup by @value{tramp} upon first connection. Alternatively, use an absolute path or extend -@option{tramp-remote-path} (see @ref{Remote programs}): +@code{tramp-remote-path} (see @ref{Remote programs}): @lisp @group @@ -2657,9 +2657,9 @@ upon first connection. Alternatively, use an absolute path or extend @end lisp @vindex tramp-remote-process-environment -Customize user option @option{tramp-remote-process-environment} to +Customize user option @code{tramp-remote-process-environment} to suit the remote program's environment for the remote host. -@option{tramp-remote-process-environment} is a list of strings +@code{tramp-remote-process-environment} is a list of strings structured similar to @code{process-environment}, where each element is a string of the form @samp{ENVVARNAME=VALUE}. @@ -2676,11 +2676,11 @@ Use @code{add-to-list} to add entries: @vindex HISTORY@r{, environment variable} Modifying or deleting already existing values in the -@option{tramp-remote-process-environment} list may not be feasible on +@code{tramp-remote-process-environment} list may not be feasible on restricted remote hosts. For example, some system administrators disallow changing @env{HISTORY} environment variable. To accommodate such restrictions when using @value{tramp}, fix the -@option{tramp-remote-process-environment} by the following code in the +@code{tramp-remote-process-environment} by the following code in the local @file{.emacs} file: @lisp @@ -2704,12 +2704,12 @@ this. You could overwrite this behavior by evaluating @end group @end lisp -In addition to @option{tramp-remote-process-environment}, you can set +In addition to @code{tramp-remote-process-environment}, you can set environment variables for individual remote process calls by let-binding @code{process-environment}. @value{tramp} applies any entries not present in the global default value of @code{process-environment} (overriding -@option{tramp-remote-process-environment} settings, if they conflict). +@code{tramp-remote-process-environment} settings, if they conflict). For example: @lisp @@ -2759,16 +2759,16 @@ local host. @subsection Running @code{shell} on a remote host @cindex @code{shell} -Set @option{explicit-shell-file-name} to the appropriate shell name +Set @code{explicit-shell-file-name} to the appropriate shell name when using @value{tramp} between two hosts with different operating systems, such as @samp{windows-nt} and @samp{gnu/linux}. This option ensures the correct name of the remote shell program. -When @option{explicit-shell-file-name} is equal to @code{nil}, calling +When @code{explicit-shell-file-name} is equal to @code{nil}, calling @code{shell} interactively will prompt for a shell name. Starting with Emacs 26, you could use connection-local variables for -setting different values of @option{explicit-shell-file-name} for +setting different values of @code{explicit-shell-file-name} for different remote hosts. @ifinfo @pxref{Connection Local Variables, , , elisp} @@ -2849,7 +2849,7 @@ uid=0(root) gid=0(root) groups=0(root) @code{eshell} added custom @code{su} and @code{sudo} commands that set the default directory correctly for the @file{*eshell*} buffer. -@value{tramp} silently updates @option{tramp-default-proxies-alist} +@value{tramp} silently updates @code{tramp-default-proxies-alist} with an entry for this directory (@pxref{Multi-hops}): @example @@ -2932,7 +2932,7 @@ relative or absolute paths, but not remote paths. command. Powershell V2.0 on the remote host is required to run processes triggered from @value{tramp}. -@option{explicit-shell-file-name} and @option{explicit-*-args} have to +@code{explicit-shell-file-name} and @code{explicit-*-args} have to be set properly so @kbd{M-x shell @key{RET}} can open a proper remote shell on a MS Windows host. To open @command{cmd}, set it as follows: @@ -3090,7 +3090,7 @@ responsiveness slows down. Some suggestions within the scope of Use an external method, such as @option{scp}, which are faster than internal methods. -Keep the file @option{tramp-persistency-file-name}, which is where +Keep the file @code{tramp-persistency-file-name}, which is where @value{tramp} caches remote information about hosts and files. Caching is enabled by default. Don't disable it. @@ -3099,7 +3099,7 @@ files are not independently updated outside @value{tramp}'s control. That cache cleanup will be necessary if the remote directories or files are updated independent of @value{tramp}. -Set @option{tramp-completion-reread-directory-timeout} to @code{nil} to +Set @code{tramp-completion-reread-directory-timeout} to @code{nil} to speed up completions, @ref{File name completion}. Disable version control to avoid delays: @@ -3354,7 +3354,7 @@ Host indication in the mode line? Install @file{tramp-theme} from GNU ELPA via Emacs' Package Manager. Enable it via @kbd{M-x load-theme @key{RET} tramp @key{RET}}. Further customization is explained in user option -@option{tramp-theme-face-remapping-alist}. +@code{tramp-theme-face-remapping-alist}. @item @@ -3385,7 +3385,7 @@ Why is @file{~/.sh_history} file on the remote host growing? Due to the remote shell saving tilde expansions triggered by @value{tramp}, the history file is probably growing rapidly. @value{tramp} can suppress this behavior with the user option -@option{tramp-histfile-override}. When set to @code{t}, environment +@code{tramp-histfile-override}. When set to @code{t}, environment variable @env{HISTFILE} is unset, and environment variables @env{HISTFILESIZE} @env{HISTSIZE} are set to 0. @@ -3681,7 +3681,7 @@ package, use the full ad-hoc file name including all hops, like Alternatively, when saving abbreviated multi-hop file names @file{@trampfn{ssh,news@@news.my.domain,/opt/news/etc}}, the user -option @option{tramp-save-ad-hoc-proxies} must be set non-@code{nil} +option @code{tramp-save-ad-hoc-proxies} must be set non-@code{nil} value. commit 6e5f19ada410a176eb36b0742fe45b3f5c80b710 Author: Michael Albinus Date: Tue May 29 12:28:01 2018 +0200 Fix Bug#31605 * doc/misc/tramp.texi (All): Add @vindex entries for environment variables. (Remote shell setup): New items `tramp-terminal-type' and "Determining a Tramp session". (Frequently Asked Questions): Adapt zsh example. (Bug#31605) diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index f78124fdcd..2960368447 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -1020,6 +1020,7 @@ can. @cindex android (with adb method) @vindex tramp-adb-program +@vindex PATH@r{, environment variable} This method uses Android Debug Bridge program for accessing Android devices. The Android Debug Bridge must be installed locally for @value{tramp} to work. Some GNU/Linux distributions provide Android @@ -1877,15 +1878,64 @@ example below: Similar localization may be necessary for handling wrong password prompts, for which @value{tramp} uses @option{tramp-wrong-passwd-regexp}. +@item @code{tramp-terminal-type} +@vindex tramp-terminal-type +@vindex TERM@r{, environment variable} + +@value{tramp} uses the user option @code{tramp-terminal-type} to set +the remote environment variable @env{TERM} for the shells it runs. +Per default, it is @samp{"dumb"}, but this could be changed. A dumb +terminal is best suited to run the background sessions of +@value{tramp}. However, running interactive remote shells might +require a different setting. This could be achieved by tweaking the +@env{TERM} environment variable in @code{process-environment}. + +@lisp +@group +(let ((process-environment + (cons "TERM=xterm-256color" process-environment))) + (shell)) +@end group +@end lisp + +@item Determining a @value{tramp} session +@vindex TERM@r{, environment variable} +@vindex INSIDE_EMACS@r{, environment variable} + +Sometimes, it is needed to identify whether a shell runs under +@value{tramp} control. The setting of environment variable @env{TERM} +will help: + +@example +@group +if test "$TERM" = "dumb"; then + ... +fi +@end group +@end example + +Another possibility is to check the environment variable +@env{INSIDE_EMACS}. Like for all subprocesses of Emacs, this is set +to the version of the parent Emacs process, @xref{Interactive Shell, , +, emacs}. @value{tramp} adds its own package version to this string, +which could be used for further tests in an inferior shell. The +string of that environment variable loooks always like + +@example +@group +echo $INSIDE_EMACS +@result{} 26.2,tramp:2.3.4 +@end group +@end example + @item @command{tset} and other questions @cindex unix command @command{tset} @cindex @command{tset} unix command -@vindex tramp-terminal-type To suppress inappropriate prompts for terminal type, @value{tramp} -sets the @env{TERM} to @code{dumb} before the remote login process -begins via the user option @option{tramp-terminal-type}. This will -silence common @command{tset} related prompts. +sets the @env{TERM} environment variable before the remote login +process begins via the user option @option{tramp-terminal-type} (see +above). This will silence common @command{tset} related prompts. @value{tramp}'s strategy for handling such prompts (commonly triggered from login scripts on remote hosts) is to set the environment @@ -1958,6 +2008,9 @@ shell-specific config files. For example, bash can use @item Interactive shell prompt +@vindex INSIDE_EMACS@r{, environment variable} +@vindex SHELLNAME@r{, environment variable} +@vindex ESHELL@r{, environment variable} @value{tramp} redefines the remote shell prompt internally for robust parsing. This redefinition affects the looks of a prompt in an interactive remote shell through commands, such as @kbd{M-x shell @@ -2248,6 +2301,7 @@ Windows file names to Cygwin file names. @cindex cygwin and @command{ssh-agent} @cindex @env{SSH_AUTH_SOCK} and emacs on ms windows +@vindex SSH_AUTH_SOCK@r{, environment variable} When using the @command{ssh-agent} on MS Windows for password-less interaction, @option{ssh} methods depend on the environment variable @@ -2620,6 +2674,7 @@ Use @code{add-to-list} to add entries: (add-to-list 'tramp-remote-process-environment "JAVA_HOME=/opt/java") @end lisp +@vindex HISTORY@r{, environment variable} Modifying or deleting already existing values in the @option{tramp-remote-process-environment} list may not be feasible on restricted remote hosts. For example, some system administrators @@ -2636,6 +2691,7 @@ local @file{.emacs} file: @end group @end lisp +@vindex ENV@r{, environment variable} Setting the @env{ENV} environment variable instructs some shells to read an initialization file. Per default, @value{tramp} has disabled this. You could overwrite this behavior by evaluating @@ -2663,6 +2719,7 @@ For example: @end group @end lisp +@vindex HGPLAIN@r{, environment variable} Let-binding in this way works regardless of whether the process to be called is local or remote, since @value{tramp} would add just the @env{HGPLAIN} setting and local processes would take whole value of @@ -2674,6 +2731,7 @@ remotely, please file a bug report. @xref{Bug Reports}. @subsection Running remote programs that create local X11 windows +@vindex DISPLAY@r{, environment variable} To allow a remote program to create an X11 window on the local host, set the @env{DISPLAY} environment variable for the remote host as follows in the local @file{.emacs} file: @@ -3098,7 +3156,7 @@ uses left-hand side and right-hand side prompts in parallel. Add the following line to @file{~/.zshrc}: @example -[ $TERM = "dumb" ] && unsetopt zle && PS1='$ ' +[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ ' && return @end example When using fish shell on remote hosts, disable fancy formatting by @@ -3321,6 +3379,9 @@ then set them with a hook as follows: Why is @file{~/.sh_history} file on the remote host growing? @vindex tramp-histfile-override +@vindex HISTFILE@r{, environment variable} +@vindex HISTFILESIZE@r{, environment variable} +@vindex HISTSIZE@r{, environment variable} Due to the remote shell saving tilde expansions triggered by @value{tramp}, the history file is probably growing rapidly. @value{tramp} can suppress this behavior with the user option @@ -3668,6 +3729,7 @@ emacsclient @trampfn{ssh,$(whoami)@@$(hostname --fqdn),$1} @end group @end example +@vindex EDITOR@r{, environment variable} Then change the environment variable @env{EDITOR} to point to the wrapper script: