Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions le-python.el
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ it at one time."
(defvar lispy--python-init-file nil)

(defun lispy--python-poetry-name ()
(let ((pyproject (expand-file-name "pyproject.toml" (counsel-locate-git-root))))
(when-let* ((bfn (buffer-file-name))
(root (locate-dominating-file bfn "pyproject.toml"))
(pyproject (expand-file-name "pyproject.toml" root)))
(and (file-exists-p pyproject)
(not (equal python-shell-interpreter "python"))
(with-current-buffer (find-file-noselect pyproject)
Expand Down Expand Up @@ -355,7 +357,8 @@ it at one time."
(buffer
(let ((python-shell-completion-native-enable nil)
(default-directory (if poetry-name
(counsel-locate-git-root)
(expand-file-name
(project-root (project-current)))
default-directory)))
(python-shell-make-comint
python-binary-name proc-name nil nil))))
Expand Down
80 changes: 44 additions & 36 deletions lispy.el
Original file line number Diff line number Diff line change
Expand Up @@ -6639,7 +6639,9 @@ Otherwise return cons of current string, symbol or list bounds."
(org-back-to-heading t)
(point))
(progn
(org-end-of-subtree t t)
(outline-mark-subtree)
(exchange-point-and-mark)
(deactivate-mark)
(when (and (org-at-heading-p)
(not (eobp)))
(backward-char 1))
Expand Down Expand Up @@ -7640,42 +7642,48 @@ Defaults to `error'."
(defun lispy--function-parse (str)
"Extract the function body and args from it's expression STR."
(let ((body (lispy--read str))
args)
(cond ((eq (car body) 'lambda)
(setq body (cons 'defun body)))
((eq (car body) 'closure)
(setq body `(defun noname ,@(cddr body))))
((eq (car body) 'defsubst)
(setq body (cons 'defun (cdr body)))))
(cond ((memq (car body) '(defun defmacro))
(setq body (lispy--whitespace-trim (cdr body))))
((eq (car body) 'defalias)
(let ((name (cadr (cadr (read str)))))
(setq body
(cons name (cdr (symbol-function name))))))
(t
(error "Expected defun, defmacro, or defalias got %s" (car body))))
(if (symbolp (car body))
(setq body (lispy--whitespace-trim (cdr body)))
(error "Expected function name, got %s" (car body)))
(if (listp (car body))
(progn
(setq args (car body))
args)
(if (not (consp body))
(progn (setq args (aref body 0))
(setq body (aref body 1)))
;; In Emacs 30, `read' returns a dedicated type, instead of
;; simple list, for lambdas, defuns, closures, etc. And code
;; below is only valid for `defmacro'. Keep it for Emacs < 30.
(cond ((eq (car body) 'lambda)
(setq body (cons 'defun body)))
((eq (car body) 'closure)
(setq body `(defun noname ,@(cddr body))))
((eq (car body) 'defsubst)
(setq body (cons 'defun (cdr body)))))
(cond ((memq (car body) '(defun defmacro))
(setq body (lispy--whitespace-trim (cdr body))))
((eq (car body) 'defalias)
(let ((name (cadr (cadr (read str)))))
(setq body
(cons name (cdr (symbol-function name))))))
(t
(error "Expected defun, defmacro, or defalias got %s" (car body))))
(if (symbolp (car body))
(setq body (lispy--whitespace-trim (cdr body)))
(error "Expected function name, got %s" (car body)))
(if (listp (car body))
(progn
(setq args (car body))
(setq body (lispy--whitespace-trim (cdr body))))
(error "Expected function arguments, got %s" (car body)))
;; skip docstring
(if (and (listp (car body))
(eq (caar body) 'ly-raw)
(eq (cadar body) 'string))
(setq body (lispy--whitespace-trim (cdr body))))
;; skip declare
(if (and (listp (car body))
(eq (caar body) 'declare))
(setq body (lispy--whitespace-trim (cdr body))))
(error "Expected function arguments, got %s" (car body)))
;; skip docstring
(if (and (listp (car body))
(eq (caar body) 'ly-raw)
(eq (cadar body) 'string))
(setq body (lispy--whitespace-trim (cdr body))))
;; skip declare
(if (and (listp (car body))
(eq (caar body) 'declare))
(setq body (lispy--whitespace-trim (cdr body))))
;; skip interactive
(if (and (listp (car body))
(eq (caar body) 'interactive))
(setq body (lispy--whitespace-trim (cdr body))))
;; skip interactive
(if (and (listp (car body))
(eq (caar body) 'interactive))
(setq body (lispy--whitespace-trim (cdr body)))))
(list args body)))

(defun lispy--flatten-function (fstr e-args)
Expand Down