New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodetect --virtual-env and --sys-path from python.el settings. #33

Merged
merged 2 commits into from Feb 12, 2013

Conversation

Projects
None yet
2 participants
@fgallina
Contributor

fgallina commented Feb 11, 2013

Vars:

  • jedi:import-python-el-settings.

Functions:

  • jedi:import-python-el-settings-setup.

Fixes #32.

Autodetect --virtual-env and --sys-path from python.el settings.
Vars:
  +  jedi:import-python-el-settings.

Functions:
  + jedi:import-python-el-settings-setup.
jedi.el Outdated
This is automatically added to the `jedi-mode-hook' when
`jedi:import-python-el-settings' is non-nil."
(let ((args))
(and (boundp 'python-shell-extra-pythonpaths)

This comment has been minimized.

@tkf

tkf Feb 11, 2013

Owner

I guess using and here is "lispy" way, but I stick to use when in this case because it is what you mean here. Indent works better with when, too. Same for other two ands in this function and one in jedi:setup.

This comment has been minimized.

@fgallina

fgallina Feb 12, 2013

Contributor

It is not only lispy but more compact. I tend to use just and when the executing body of what would be a when is just a sexp. Here's the when version, as you see I'm not using and but the indentation is also similar (and greater in predicates) than what's sent:

(defun jedi:import-python-el-settings-setup ()
  "Make jedi aware of python.el virtualenv and path settings.
This is automatically added to the `jedi-mode-hook' when
`jedi:import-python-el-settings' is non-nil."
  (let ((args))
    (when (and (boundp 'python-shell-extra-pythonpaths)
               python-shell-extra-pythonpaths)
      (mapc
       (lambda (path)
         (setq args (append (list "--sys-path" path) args)))
       python-shell-extra-pythonpaths))
    (when (and (boundp 'python-shell-virtualenv-path)
               python-shell-virtualenv-path)
      (setq args
            (append
             (list "--virtual-env" python-shell-virtualenv-path)
             args)))
    (when args (set (make-local-variable 'jedi:server-args) args))))

And even with and, you can have a more compact indent, just I didn't choose to use it, but here's the example:

(defun jedi:import-python-el-settings-setup ()
  "Make jedi aware of python.el virtualenv and path settings.
This is automatically added to the `jedi-mode-hook' when
`jedi:import-python-el-settings' is non-nil."
  (let ((args))
    (and
     (boundp 'python-shell-extra-pythonpaths)
     python-shell-extra-pythonpaths
     (mapc
      (lambda (path)
        (setq args (append (list "--sys-path" path) args)))
      python-shell-extra-pythonpaths))
    (and
     (boundp 'python-shell-virtualenv-path)
     python-shell-virtualenv-path
     (setq args
           (append
            (list "--virtual-env" python-shell-virtualenv-path)
            args)))
    (and args (set (make-local-variable 'jedi:server-args) args))))

From the readability standpoint I would agree when might feel more natural for some, but the and shouldn't be a weird thing either, because the execution is straightforward (and check this, and check that and do this).

I would change the stuff right-away but short-circuitry is beautiful and I feel it deserved some defense words in favor :)

This comment has been minimized.

@tkf

tkf Feb 12, 2013

Owner

I like readable code than compact code, that's why I prefer when. I just try to follow the zen of Python even if it is not Python.

Also, what I mean by indentation is not about making code small in width. It's about

(and
 COND
 DO-SOMETHING)

vs

(when
    COND
  DO-SOMETHING)

(though I put when and COND in the same line almost always).

I agree and is good for sometime when you want to write a chain of action. For example I define aand or and-let* in big project. But I avoid and when I can because and is more flexible (thus takes time to get the meaning of the code) than when. By the same reason, I use when instead of if when there is no else clause.

This comment has been minimized.

@tkf

tkf Feb 12, 2013

Owner

BTW, we should use bound-and-true-p instead of boundp here. It is defined at least in Emacs 23.1.

@tkf

This comment has been minimized.

Owner

tkf commented Feb 11, 2013

Thanks, code looks good other than the nitpick I mentioned. I should have mentioned when I read your suggestion in the other issue.

@fgallina

This comment has been minimized.

Contributor

fgallina commented Feb 12, 2013

Fair enough, this commit should be enough.

@tkf

This comment has been minimized.

Owner

tkf commented Feb 12, 2013

Thank you for your patience, I'll merge it right after Travis build.

tkf added a commit that referenced this pull request Feb 12, 2013

Merge pull request #33 from fgallina/python-el-integration
Autodetect --virtual-env and --sys-path from python.el settings.

@tkf tkf merged commit 60d76f9 into tkf:master Feb 12, 2013

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment