diff options
| -rw-r--r-- | lisp/progmodes/python.el | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index a582dc6db2a..860f0859b01 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1152,13 +1152,13 @@ run). | |||
| 1152 | (proc-buffer-name (format "*%s*" proc-name)) | 1152 | (proc-buffer-name (format "*%s*" proc-name)) |
| 1153 | (process-environment | 1153 | (process-environment |
| 1154 | (if python-shell-process-environment | 1154 | (if python-shell-process-environment |
| 1155 | (merge 'list python-shell-process-environment | 1155 | (python-util-merge 'list python-shell-process-environment |
| 1156 | process-environment 'string=) | 1156 | process-environment 'string=) |
| 1157 | process-environment)) | 1157 | process-environment)) |
| 1158 | (exec-path | 1158 | (exec-path |
| 1159 | (if python-shell-exec-path | 1159 | (if python-shell-exec-path |
| 1160 | (merge 'list python-shell-exec-path | 1160 | (python-util-merge 'list python-shell-exec-path |
| 1161 | exec-path 'string=) | 1161 | exec-path 'string=) |
| 1162 | exec-path))) | 1162 | exec-path))) |
| 1163 | (when (not (comint-check-proc proc-buffer-name)) | 1163 | (when (not (comint-check-proc proc-buffer-name)) |
| 1164 | (let ((cmdlist (split-string-and-unquote cmd))) | 1164 | (let ((cmdlist (split-string-and-unquote cmd))) |
| @@ -1956,7 +1956,7 @@ Interactively, prompt for symbol." | |||
| 1956 | :group 'python | 1956 | :group 'python |
| 1957 | :safe 'booleanp) | 1957 | :safe 'booleanp) |
| 1958 | 1958 | ||
| 1959 | (defcustom python-imenu-make-tree nil | 1959 | (defcustom python-imenu-make-tree t |
| 1960 | "Non-nil make imenu to build a tree menu. | 1960 | "Non-nil make imenu to build a tree menu. |
| 1961 | Set to nil for speed." | 1961 | Set to nil for speed." |
| 1962 | :type 'boolean | 1962 | :type 'boolean |
| @@ -1992,7 +1992,8 @@ Argument PLAIN-INDEX is the calculated plain index used to build the tree." | |||
| 1992 | (mapconcat #'identity full-element ".") | 1992 | (mapconcat #'identity full-element ".") |
| 1993 | plain-index))) | 1993 | plain-index))) |
| 1994 | (subelement-name (car element-list)) | 1994 | (subelement-name (car element-list)) |
| 1995 | (subelement-position (position subelement-name full-element)) | 1995 | (subelement-position (python-util-position |
| 1996 | subelement-name full-element)) | ||
| 1996 | (subelement-path (when subelement-position | 1997 | (subelement-path (when subelement-position |
| 1997 | (butlast | 1998 | (butlast |
| 1998 | full-element | 1999 | full-element |
| @@ -2045,10 +2046,10 @@ This tree gets built: | |||
| 2045 | Internally it uses `python-imenu-make-element-tree' to create all | 2046 | Internally it uses `python-imenu-make-element-tree' to create all |
| 2046 | branches for each element." | 2047 | branches for each element." |
| 2047 | (setq python-imenu-index-alist nil) | 2048 | (setq python-imenu-index-alist nil) |
| 2048 | (mapcar (lambda (element) | 2049 | (mapc (lambda (element) |
| 2049 | (python-imenu-make-element-tree element element index)) | 2050 | (python-imenu-make-element-tree element element index)) |
| 2050 | (mapcar (lambda (element) | 2051 | (mapcar (lambda (element) |
| 2051 | (split-string (car element) "\\." t)) index)) | 2052 | (split-string (car element) "\\." t)) index)) |
| 2052 | python-imenu-index-alist) | 2053 | python-imenu-index-alist) |
| 2053 | 2054 | ||
| 2054 | (defun python-imenu-create-index () | 2055 | (defun python-imenu-create-index () |
| @@ -2195,6 +2196,29 @@ character address of the specified TYPE." | |||
| 2195 | (t nil)))) | 2196 | (t nil)))) |
| 2196 | 2197 | ||
| 2197 | 2198 | ||
| 2199 | ;;; Utility functions | ||
| 2200 | |||
| 2201 | ;; Stolen from GNUS | ||
| 2202 | (defun python-util-merge (type list1 list2 pred) | ||
| 2203 | "Destructively merge lists LIST1 and LIST2 to produce a new list. | ||
| 2204 | Argument TYPE is for compatibility and ignored. | ||
| 2205 | Ordering of the elements is preserved according to PRED, a `less-than' | ||
| 2206 | predicate on the elements." | ||
| 2207 | (let ((res nil)) | ||
| 2208 | (while (and list1 list2) | ||
| 2209 | (if (funcall pred (car list2) (car list1)) | ||
| 2210 | (push (pop list2) res) | ||
| 2211 | (push (pop list1) res))) | ||
| 2212 | (nconc (nreverse res) list1 list2))) | ||
| 2213 | |||
| 2214 | (defun python-util-position (item seq) | ||
| 2215 | "Find the first occurrence of ITEM in SEQ. | ||
| 2216 | Return the index of the matching item, or nil if not found." | ||
| 2217 | (let ((member-result (member item seq))) | ||
| 2218 | (when member-result | ||
| 2219 | (- (length seq) (length member-result))))) | ||
| 2220 | |||
| 2221 | |||
| 2198 | ;;;###autoload | 2222 | ;;;###autoload |
| 2199 | (define-derived-mode python-mode fundamental-mode "Python" | 2223 | (define-derived-mode python-mode fundamental-mode "Python" |
| 2200 | "Major mode for editing Python files. | 2224 | "Major mode for editing Python files. |