Skip to content
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

Forced to jedi:install-server everytime emacs starts #280

Open
jaseemabid opened this issue Feb 20, 2017 · 11 comments
Open

Forced to jedi:install-server everytime emacs starts #280

jaseemabid opened this issue Feb 20, 2017 · 11 comments

Comments

@jaseemabid
Copy link

Jedi works fine after the installation, but its painful to do this every time emacs hangs, which is pretty often these days.

Any tips on how to debug?

@syohex
Copy link
Collaborator

syohex commented Feb 21, 2017

Hmm, its strange. If dependencies are installed once, you need not to install dependencies again. Do you remove its directory(~/.emacs.d/.python-environments/) at every emacs start or quit ?

Any tips on how to debug?

Sorry I have no idea. I suppose you can avoid this issue by installing jedi.el dependencies into your python environment(by pip install jedi && pip install epc).

@jaseemabid
Copy link
Author

@syohex Here is my config if that helps.

(use-package jedi
  :config
  (add-hook 'python-mode-hook 'jedi:setup)
  (setq jedi:complete-on-dot t
        jedi:use-shortcuts t
        jedi:environment-root "jedi"
        python-environment-directory "~/.virtualenvs"))

@alamaison
Copy link

I have the same problem:

Traceback (most recent call last):
  File "/home/alex/.emacs.d/elpa/jedi-core-20170121.610/jediepcserver.py", line 327, in <module>
    main()
  File "/home/alex/.emacs.d/elpa/jedi-core-20170121.610/jediepcserver.py", line 321, in main
    server = jedi_epc_server(**vars(ns))
  File "/home/alex/.emacs.d/elpa/jedi-core-20170121.610/jediepcserver.py", line 228, in jedi_epc_server
    import_jedi()
  File "/home/alex/.emacs.d/elpa/jedi-core-20170121.610/jediepcserver.py", line 274, in import_jedi
    import jedi
ImportError: No module named jedi

Process epc:server:2 exited abnormally with code 1

I've checked the contents of ~/.emacs.d/.python-environments and it's the same before and after emacs starts:

Before:

$> ls -l ~/.emacs.d/.python-environments/*/*
-rw-rw-r-- 1 alex alex   60 Dec 11 17:57 /home/alex/.emacs.d/.python-environments/jedi/pip-selfcheck.json

/home/alex/.emacs.d/.python-environments/jedi/bin:
total 4404
-rw-rw-r-- 1 alex alex    2104 Nov 21 15:19 activate
-rw-rw-r-- 1 alex alex    1046 Nov 21 15:19 activate.csh
-rw-rw-r-- 1 alex alex    2200 Nov 21 15:19 activate.fish
-rw-rw-r-- 1 alex alex    1137 Nov 21 15:19 activate_this.py
-rwxrwxr-x 1 alex alex     275 Nov 21 15:19 easy_install
-rwxrwxr-x 1 alex alex     275 Nov 21 15:19 easy_install-3.5
-rwxrwxr-x 1 alex alex     257 Dec 12 17:42 jediepcserver
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip3
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip3.5
lrwxrwxrwx 1 alex alex       7 Nov 21 15:19 python -> python3
-rwxrwxr-x 1 alex alex 4460336 Nov 21 15:19 python3
lrwxrwxrwx 1 alex alex       7 Nov 21 15:19 python3.5 -> python3
-rwxrwxr-x 1 alex alex    2363 Nov 21 15:19 python-config
-rwxrwxr-x 1 alex alex     254 Nov 21 15:19 wheel

/home/alex/.emacs.d/.python-environments/jedi/include:
total 0
lrwxrwxrwx 1 alex alex 23 Nov 21 15:19 python3.5m -> /usr/include/python3.5m

/home/alex/.emacs.d/.python-environments/jedi/lib:
total 4
drwxrwxr-x 5 alex alex 4096 Nov 21 15:19 python3.5

After:

$> ls -l ~/.emacs.d/.python-environments/*/*
-rw-rw-r-- 1 alex alex   60 Dec 11 17:57 /home/alex/.emacs.d/.python-environments/jedi/pip-selfcheck.json

/home/alex/.emacs.d/.python-environments/jedi/bin:
total 4404
-rw-rw-r-- 1 alex alex    2104 Nov 21 15:19 activate
-rw-rw-r-- 1 alex alex    1046 Nov 21 15:19 activate.csh
-rw-rw-r-- 1 alex alex    2200 Nov 21 15:19 activate.fish
-rw-rw-r-- 1 alex alex    1137 Nov 21 15:19 activate_this.py
-rwxrwxr-x 1 alex alex     275 Nov 21 15:19 easy_install
-rwxrwxr-x 1 alex alex     275 Nov 21 15:19 easy_install-3.5
-rwxrwxr-x 1 alex alex     257 Dec 12 17:42 jediepcserver
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip3
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip3.5
lrwxrwxrwx 1 alex alex       7 Nov 21 15:19 python -> python3
-rwxrwxr-x 1 alex alex 4460336 Nov 21 15:19 python3
lrwxrwxrwx 1 alex alex       7 Nov 21 15:19 python3.5 -> python3
-rwxrwxr-x 1 alex alex    2363 Nov 21 15:19 python-config
-rwxrwxr-x 1 alex alex     254 Nov 21 15:19 wheel

/home/alex/.emacs.d/.python-environments/jedi/include:
total 0
lrwxrwxrwx 1 alex alex 23 Nov 21 15:19 python3.5m -> /usr/include/python3.5m

/home/alex/.emacs.d/.python-environments/jedi/lib:
total 4
drwxrwxr-x 5 alex alex 4096 Nov 21 15:19 python3.5

After running M-x jedi:install-server the only difference in the timestamp of the binary:

$> ls -l ~/.emacs.d/.python-environments/*/*
-rw-rw-r-- 1 alex alex   60 Dec 21 14:42 /home/alex/.emacs.d/.python-environments/jedi/pip-selfcheck.json

/home/alex/.emacs.d/.python-environments/jedi/bin:
total 4404
-rw-rw-r-- 1 alex alex    2104 Nov 21 15:19 activate
-rw-rw-r-- 1 alex alex    1046 Nov 21 15:19 activate.csh
-rw-rw-r-- 1 alex alex    2200 Nov 21 15:19 activate.fish
-rw-rw-r-- 1 alex alex    1137 Nov 21 15:19 activate_this.py
-rwxrwxr-x 1 alex alex     275 Nov 21 15:19 easy_install
-rwxrwxr-x 1 alex alex     275 Nov 21 15:19 easy_install-3.5
-rwxrwxr-x 1 alex alex     257 Dec 21 14:42 jediepcserver
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip3
-rwxrwxr-x 1 alex alex     247 Nov 21 15:19 pip3.5
lrwxrwxrwx 1 alex alex       7 Nov 21 15:19 python -> python3
-rwxrwxr-x 1 alex alex 4460336 Nov 21 15:19 python3
lrwxrwxrwx 1 alex alex       7 Nov 21 15:19 python3.5 -> python3
-rwxrwxr-x 1 alex alex    2363 Nov 21 15:19 python-config
-rwxrwxr-x 1 alex alex     254 Nov 21 15:19 wheel

/home/alex/.emacs.d/.python-environments/jedi/include:
total 0
lrwxrwxrwx 1 alex alex 23 Nov 21 15:19 python3.5m -> /usr/include/python3.5m

/home/alex/.emacs.d/.python-environments/jedi/lib:
total 4
drwxrwxr-x 5 alex alex 4096 Nov 21 15:19 python3.5

@alamaison
Copy link

My init.el looks like this:

(use-package jedi-core
  :ensure
  :config
  (setq jedi:use-shortcuts t) ; M-. and M-,
  (add-hook 'python-mode-hook 'jedi:setup)
  (setq jedi:environment-root "jedi")
  (setq jedi:environment-virtualenv
        (append python-environment-virtualenv
                '("--python" "/usr/bin/python3")))
  (use-package company-jedi
    :ensure
    :config
    (add-hook 'python-mode-hook
              (lambda () (add-to-list 'company-backends
                                      'company-jedi)))))

@immerrr
Copy link
Collaborator

immerrr commented Nov 7, 2018

@jaseemabid could you try the current master and see if the issue persists?

@wfedorko
Copy link

wfedorko commented May 5, 2019

Hello - has this been solved - I seem to be running into the same issue

@immerrr
Copy link
Collaborator

immerrr commented May 6, 2019

@wfedorko can you confirm that the issue persists on the current master branch?

@4lph4-Ph4un
Copy link

Same issue too. Persists in current master. I have identical configuration to alamaison.

@immerrr
Copy link
Collaborator

immerrr commented Jul 19, 2019

@4lph4-Ph4un thank you! That's one piece of information nailed down.

Can you provide the entire init.el? use-package is a 3rdparty library that is not enabled by default. You can copy parts of init.el into a separate file that you can then load with emacs -Q -l repro-init.el. That way we can ensure that the issue is not related to other libraries and/or load order.

And I presume the issue is the same, right? Cannot import jedi module?

@immerrr
Copy link
Collaborator

immerrr commented Jul 19, 2019

I'll try to come up with an init.el myself, but it is always better to have a repro environment that is as close as possible to the failing one.

@4lph4-Ph4un
Copy link

4lph4-Ph4un commented Jul 21, 2019

@immerrr, sorry was a bit hectic weekend. :) Here's my init.el. I actually simplified the config from the original due to my intention to have auto-virtualenvwrapper to set the virtualenv for me according to each project, but got the same error still (Cannot import jedi module).

If my init -looks a bit weird it's because I use a system where I have the configs documented inside org-file snippets that then get concatenated into my main emacs-configuration - You'll likely have to improvise around that:

(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)

;; Defining platform flags:
(setq timsa-aquamacs (featurep 'aquamacs))
(setq timsa-linux    (featurep 'x))
(setq timsa-win      (not (or timsa-linux timsa-aquamacs)))

;; Platform level utilities:
;; Window commands:
(defun w32-restore-frame ()
  "Restore a minimized frame."
  (interactive)
  (w32-send-sys-command 61728))

(defun maximize-frame ()
  "Maximize the current frame."
  (interactive)
  (when timsa-aquamacs (aquamacs-toggle-full-frame))
  (when timsa-win      (w32-send-sys-command 61488)))

(defun setup-mingw32 ()
  "Set PATH for mingw32"
  (interactive)
  (message "Setting PATH for mingw32")
  (setenv "PATH"
          (concat
           (getenv "PATH") ";"
           "C:\\msys32\\usr\\bin" ";"
           "C:\\msys32\\mingw32\\bin" ";"))
  (setq exec-path
        (append '("c:/msys32/usr/bin"
                  "c:/msys32/mingw32/bin")
                exec-path)))

(define-key global-map "\ep" 'maximize-frame)

;; Initialize system level behavior according to flags:
;; NOTE: build setup is deprecated and awaits for modiciations:
(if (or timsa-linux timsa-aquamacs)
    (progn
      (if timsa-linux         
          (if (> (string-to-number
                  (shell-command-to-string "grep -c 'Microsoft' /proc/version"))
                 0)
              (progn
                (message "WSL detected - Initalizing TIMSA-WSL")
                (setq timsa-wsl t))
            (progn
              (message "NIX detected - Initializing TIMSA-LINUX")
              (setq timsa-wsl nil)))
        (message "OSX detected - Initializing TIMSA-AQUAMACS"))
      (set-variable 'grep-command "grep -irHn "))
  (progn
    (message "Windows detected - Initializing TIMSA-WIN")
    (setup-mingw32)
    ;; Setting external search paths:
    ;; NOTE: Waiting for more extensive Carp support for Win:
    (setq timsa-wsl nil)
    (set-variable 'grep-command "findstr -s -n -i -l ")))

(use-package doom-themes
  :ensure t
  :init (add-hook 'after-init-hook
                  (lambda ()
                    (load-theme 'doom-molokai t)))
  :config (doom-themes-org-config))

(add-to-list 'default-frame-alist '(font . "Fira Code-8"))

;; Mode -level specifics:
(setq fixme-modes '(c++-mode
                    c-mode
                    web-mode
                    ruby-mode
                    python-mode
                    lua-mode
                    lisp-mode
                    clojure-mode
                    graphviz-dot-mode
                    haskell-mode))
(make-face 'font-lock-fixme-face)
(make-face 'font-lock-study-face)
(make-face 'font-lock-important-face)
(make-face 'font-lock-note-face)
(mapc (lambda (mode)
    (font-lock-add-keywords
     mode
     '(("\\<\\(TODO\\)"      1 'font-lock-fixme-face     t)
       ("\\<\\(STUDY\\)"     1 'font-lock-study-face     t)
       ("\\<\\(IMPORTANT\\)" 1 'font-lock-important-face t)
       ("\\<\\(NOTE\\)"      1 'font-lock-note-face      t))))
      fixme-modes)
(modify-face 'font-lock-fixme-face     "#F92672" nil nil t nil t nil nil)
(modify-face 'font-lock-study-face     "#66D9EF" nil nil t nil t nil nil)
(modify-face 'font-lock-important-face "#E6DB74" nil nil t nil t nil nil)
(modify-face 'font-lock-note-face      "#FD5FF0" nil nil t nil t nil nil)

;; General settings for frame and window:
(setq frame-title-format     "emacs")
(setq next-line-add-newlines nil)
(setq-default truncate-lines    t)
(setq-default indent-tabs-mode  nil)
(setq-default shift-select-mode nil)
(setq truncate-partial-width-windows nil)
(split-window-horizontally)
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode -1)
(electric-pair-mode 1)
(display-time)

(setq linum-format "%3d \u2502")

;; High undo limit:
(setq undo-limit 20000000)
(setq undo-strong-limit 40000000)

;; Accepting short answers:
(defalias 'yes-or-no-p 'y-or-n-p)

;; UTF-8:
(set-language-environment    "UTF-8")
(set-default-coding-systems  'utf-8)
(setq locale-coding-system   'utf-8)
(set-terminal-coding-system  'utf-8)
(set-keyboard-coding-system  'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system        'utf-8)

(column-number-mode)
(show-paren-mode)
(setq enable-local-variables nil)
(setq scroll-step 3)

;; Disable mouse center button:
(global-unset-key [mouse-2])
(setq mouse-wheel-follow-mouse nil
      mouse-wheel-progressive-speed nil
      mouse-wheel-scroll-amount (quote (15)))

(define-key global-map [S-tab]   'indent-for-tab-command)
(define-key global-map [backtab] 'indent-for-tab-command)
(define-key global-map "\C-y"    'indent-for-tab-command)
(define-key global-map [C-tab]   'indent-region)

;; TXT mode handling
(add-hook 'text-mode-hook
      (lambda ()
        (setq tab-width 2)
        ;; Newline indents, semi-colon doesn't
        (define-key text-mode-map "\C-m" 'newline-and-indent)
        ;; Prevent overriding of alt-s
        (define-key text-mode-map "\es" 'timsa-save-buffer)))

(setq common-lisp-style "sbcl")

(add-hook 'asm-mode-hook
          (lambda()
            (setq indent-tabs-mode     nil)
            (setq electric-indent-mode -1)
            (setq tab-stop-list        (number-sequence 8 60 8))))

(add-hook 'makefile-mode-hook
  (lambda ()
    (setq indent-tabs-mode t)
    (setq tab-width        2)
    (setq-default indent-tabs-mode t)))

(use-package auto-complete
  :hook (web-mode
         lua-mode
         ruby-mode)
  :config
  ;; require default config, but disable the
  ;; global-auto-complete-mode that gets automatically
  ;; turned on:
  (require 'auto-complete-config)
  (ac-config-default)
  (global-auto-complete-mode 0))

(use-package org
  :ensure t
  :bind (("\C-cl" . org-store-link)
         ("\C-cc" . org-capture)
         ("\C-ca" . org-agenda))
  :hook (org-mode . (lambda () (setq truncate-lines nil)))
  :config
  (use-package org-pdfview :ensure t)
  (add-to-list 'org-latex-packages-alist '("" "minted"))
  (setq org-startup-indented         t
        org-startup-truncated        nil
        org-src-tab-acts-natively    t
        org-src-preserve-indentation nil
        org-src-fontify-natively     t
        org-babel-load-languages     '((emacs-lisp . t)
                                       (sh         . t)
                                       (dot        . t)
                                       (python     . t))
        org-latex-listings           'minted
        org-export-latex-listings    'minted)
  (setq org-latex-pdf-process
        '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
          "bibtex %b"
          "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
          "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
  (setq org-log-done t))

(use-package htmlize :ensure t)

(use-package projectile
  :ensure t
  :bind-keymap ("C-c p" . projectile-command-map)
  :config (projectile-global-mode))

(use-package markdown-mode
  :ensure t
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'"       . gfm-mode)
         ("\\.markdown\\'" . gfm-mode))
  :init (setq markdown-command
              (concat
               "pandoc"
               " --from=markdown --to=html"
               " --standalone --mathjax"
               " --highlight-style=pygments"))
  :hook (markdown-mode . (lambda () (setq truncate-lines nil)))
  :config
  (setq markdown-fontify-code-blocks-natively t))

(use-package paredit
  :ensure t
  :hook (((emacs-lisp-mode
           lisp-mode
           carp-mode
           clojure-mode
           slime-repl-mode
           cider-repl-mode)
          . paredit-mode))
  :bind (:map paredit-mode-map
         ("M-("         . paredit-wrap-sexp)
         ("M-["         . paredit-wrap-square)
         ("M-{"         . paredit-wrap-curly)
         ("C-M-f"       . paredit-forward)
         ("C-M-b"       . paredit-backward)
         ("C-M-d"       . paredit-forward-down)
         ("C-M-u"       . paredit-backward-up)
         ("C-M-p"       . paredit-backward-down)
         ("C-M-n"       . paredit-forward-up)
         ("C-k"         . paredit-kill)
         ("M-d"         . paredit-forward-kill-word)
         ("C-d"         . paredit-forward-delete)
         ("C-<right>"   . paredit-forward-slurp-sexp)
         ("C-<left>"    . paredit-forward-barf-sexp)
         ("C-M-<left>"  . paredit-backward-slurp-sexp)
         ("C-M-<right>" . paredit-backward-barf-sexp)
         ("M-<up>"      . paredit-splice-sexp-killing-backward)
         ("M-<down>"    . paredit-splice-sexp-killing-forward)
         ("M-s"         . nil)
         ("M-a"         . paredit-splice-sexp)
         ("M-?"         . paredit-convolute-sexp)
         ("M-J"         . paredit-join-sexps)
         ("M-S"         . paredit-split-sexps)))

(use-package slime
  :ensure t
  :config
  (use-package slime-company
    :ensure t
    :defer  t
    :config 
    (setq slime-company-completion  'fuzzy)
    (setq slime-company-major-modes '(lisp-mode
                                      slime-mode
                                      slime-repl-mode)))
  (if timsa-win
      (progn
        (setq inferior-lisp-program "sbcl.exe")
        (load (expand-file-name "C:/quicklisp/slime-helper.el")))
    (setq inferior-lisp-program "/usr/local/bin/sbcl"))
  ;; slime-repl-ansi-color required a file to be copied into vendors:
  (slime-setup '(slime-fancy slime-company slime-asdf slime-cl-indent)))

(add-to-list 'load-path 
             (concat (getenv "HOME") "/.emacs.d/externals/kickasm-mode"))
(if (not (require 'kickasm-mode nil t))
      (message "KickAsm-Mode not found!!!")
  (progn
    (setq kickasm-command-start-indent 8)
    (add-to-list 'auto-mode-alist
                 '("\\.asm\\'" . kickasm-mode))
    (add-to-list 'auto-mode-alist
                 '("\\.s\\'"   . kickasm-mode))))

(use-package cc-mode
  :ensure t
  :bind (:map c++-mode-map
              ("\C-m" . newline-and-indent)
              :map c-mode-map
              ("\C-m" . newline-and-indent))
  :hook (c++-mode . modern-c++-font-lock-mode)
  :mode (("\\.c\\'" . c++-mode)
         ("\\.h\\'" . c++-mode)
         ("\\.m\\'" . objc-mode))
  :config
  ;; C/C++ -settings:
  ;; Fix shittiness in c++11/44 -lambdas:
  (defadvice c-lineup-arglist (around my activate)
    "Improve indentation of continued C++11 lambda function opened as argument."
    (setq ad-return-value
          (if (and (equal major-mode 'c++-mode)
                   (ignore-errors
                     (save-excursion
                       (goto-char (c-langelem-pos langelem))
                       ;; Detect "[...](" or "[...]{". preceded by "," or "(",
                       ;; and with unclosed brace.
                       (looking-at ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
              0         ; no additional indent
            ad-do-it))) ; default behavior

  (setq c-hanging-semi&comma-criteria '((lambda () 'stop)))
  ;; C++ indentation style:
  (defconst timsa-cpp-style
    '((c-electric-pound-behavior  . nil)
      (c-tab-always-indent        . nil)
      (c-comment-only-line-offset . 0)
      (c-hanging-braces-alist     . ((class-open)
                                     (class-close)
                                     (defun-open)
                                     (defun-close)
                                     (inline-open)
                                     (inline-close)
                                     (brace-list-open)
                                     (brace-list-close)
                                     (brace-list-intro)
                                     (brace-list-entry)
                                     (block-open)
                                     (block-close)
                                     (substatement-open)
                                     (statement-case-open)
                                     (class-open)))
      (c-hanging-colons-alist     . ((inher-intro)
                                     (case-label)
                                     (label)
                                     (access-label)
                                     (access-key)
                                     (member-init-intro)))
      (c-cleanup-list             . (scope-operator
                                     list-close-comma
                                     defun-close-semi))
      (c-offsets-alist            . ((arglist-close        .  c-lineup-arglist)
                                     (arglist-cont         .  c-lineup-arglist-operators) 
                                     (label                . -4)
                                     (access-label         . -4)
                                     (substatement-open    .  0)
                                     (statement-case-intro .  4)
                                     (statement-cont       .  (c-lineup-cascaded-calls c-lineup-math))
                                     (case-label           .  0)
                                     (block-open           .  0)
                                     (inline-open          .  0)
                                     (topmost-intro-cont   .  c-lineup-cascaded-calls)
                                     (knr-argdecl-intro    . -4)
                                     (brace-list-open      .  0)
                                     (brace-list-intro     .  4)))
      (c-echo-syntactic-information-p . t))
    "Timsa's Prototype C++ Syntax!!!")
  (add-hook 'c-mode-common-hook
            (lambda ()
              (setq tab-width        4
                    indent-tabs-mode nil)
              ;; line-numbering!
              (linum-mode t)
              (c-add-style "CppTimsaJitsu" timsa-cpp-style t))))

(use-package cider
  :ensure t
  :config (setq cider-test-show-report-on-success t))

(use-package clojure-mode
  :ensure t
  :hook (clojure-mode . (lambda () (linum-mode t))))

(use-package web-mode
  :ensure t
  :hook (web-mode . (lambda ()
                      (setq web-mode-markup-indent-offset             2
                            web-mode-css-indent-offset                2
                            web-mode-code-indent-offset               2
                            web-mode-enable-current-element-highlight t
                            web-mode-enable-current-column-highlight  t
                            web-mode-style-padding                    0
                            web-mode-script-padding                   0
                            web-mode-block-padding                    0)
                      (linum-mode t)))
  :bind (:map web-mode-map
              ([S-tab]   . indent-for-tab-command)
              ([C-tab]   . indent-region)
              ([backtab] . indent-for-tab-command))
  :mode (("\\.phtml\\'"     . web-mode)
         ("\\.tpl\\.php\\'" . web-mode)
         ("\\.[agj]sp\\'"   . web-mode)
         ("\\.as[cp]x\\'"   . web-mode)
         ("\\.erb\\'"       . web-mode)
         ("\\.mustache\\'"  . web-mode)
         ("\\.djhtml\\'"    . web-mode)
         ("\\.htm[l]?\\'"   . web-mode)
         ("\\.js[x]?\\'"    . web-mode)
         ("\\.json\\'"      . web-mode)
         ("\\.[s]?css\\'"   . web-mode)
         ("\\.api\\'"       . web-mode))
  :config
  ;; Fallback *.jsx -indentaatiolle:
  (setq web-mode-content-types-alist
        '(("jsx" . "\\.js[x]?\\'"))))

(use-package yaml-mode :ensure t)

(use-package lua-mode :ensure t)

(use-package haskell-mode
  :ensure t
  :init (when (eq 25 emacs-major-version)
          (defun sanityinc/inhibit-brakcet-inside-comment-or-default (ch)
            (or (nth 4 (syntax-pss))
                (funcall #'electric-pair-default-inhibit ch))))
  :hook (haskell-mode . (lambda ()
                          (setq-local
                           electric-pair-inhibit-predicate
                           'sanityinc/inhibit-brakcet-inside-comment-or-default))))

;; NOTE: CARP-MODE currently only works on NIX and OSX:
;; We do this in such "old-fashioned way"
;; since Carp-Mode is not yet available
;; from package managers:
(add-to-list 'load-path
             (concat (getenv "HOME") "/.emacs.d/externals/carp-mode"))
(if (not (or (require 'carp-mode     nil t)
             (require 'inf-carp-mode nil t)
             (require 'carp-flycheck nil t)))
    (message "Carp-Mode not found!!!")
  (add-to-list 'auto-mode-alist
               '("\\.carp\\'" . carp-mode)))

(use-package auto-virtualenvwrapper
  :ensure t
  :hook ((python-mode . auto-virtualenvwrapper-activate)))

(use-package graphviz-dot-mode
  :ensure t
  :mode ("\\.dot\\'" . graphviz-dot-mode))

(use-package flyspell
  :ensure t
  :hook ((text-mode . flyspell-mode)
         ((emacs-lisp-mode
          lisp-mode
          carp-mode
          clojure-mode
          c-mode
          c++-mode
          haskell-mode
          graphviz-dot-mode
          web-mode
          python-mode)
         . flyspell-prog-mode))
  :config
  (use-package ispell :ensure t)
  (setenv "DICPATH" 
          (concat (getenv "HOME") "/.emacs.d/dicts"))
  (setq ispell-program-name
        (cond (timsa-linux
               "/usr/bin/hunspell")
              (timsa-win
               "C:\\Program Files (x86)\\hunspell\\bin\\hunspell.exe"))))

(use-package flycheck
  :ensure t
  :hook (((c-mode
           c++-mode
           carp-mode
           python-mode)
          . flycheck-mode)
         ((c-mode c++-mode)
          . flycheck-pos-tip-mode))
  :config 
  (use-package flycheck-pos-tip :ensure t))

(use-package flycheck-irony
  :ensure t
  :init (add-hook 'flycheck-mode-hook #'flycheck-irony-setup))

(use-package irony
  :ensure t
  :defer t
  :commands irony-mode
  :bind (:map irony-mode-map
              ([remap completion-at-point] . irony-completion-at-point-async)
              ([remap complete-symbol]     . irony-completion-at-point-async))
  :init (add-hook 'c-mode-hook #'irony-mode)
        (add-hook 'c++-mode-hook #'irony-mode)
  :config
  (when (boundp 'w32-pipe-read-delay)
    (setq w32-pipe-read-delay 0))
  (when (boundp 'w32-pipe-buffer-size)
    (setq irony-server-w32-pipe-buffer-size (* 64 1024)))
  (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))

(use-package company-jedi
  :ensure t
  :config
  (use-package jedi-core
    :ensure t
    :hook ((python-mode . jedi:setup))
    :config
    (setq jedi:use-shortcuts              t
          jedi:complete-on-dot            t
          jedi:get-in-function-call-delay 0.5
          jedi:environment-root           "jedi")))

(use-package company
  :ensure t
  :defer t
  :init (add-hook 'after-init-hook #'global-company-mode)
  :bind (:map company-active-map
              ("C-k" . company-select-next)
              ("C-i" . company-select-previous))
  :config
  (use-package company-c-headers
    :ensure t
    :defer t
    :config
    (when timsa-win
      (add-to-list
       'company-c-headers-path-system 
       "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/atlmfc/include/")
      (add-to-list
       'company-c-headers-path-system
       "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/include/")
      (add-to-list
       'company-c-headers-path-system  
       "C:/Program Files (x86)/Windows Kits/NETFXSDK/4.6.1/Include/um/")
      (add-to-list
       'company-c-headers-path-system
       "C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt/")
      (add-to-list
       'company-c-headers-path-system
       "C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/shared/")
      (add-to-list
       'company-c-headers-path-system
       "C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/um/")
      (add-to-list
       'company-c-headers-path-system
       "C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/winrt/")))
  (use-package company-irony           :ensure t)
  (use-package company-irony-c-headers :ensure t)
  (setq company-idle-delay            1
        company-minimum-prefix-length 1
        company-show-numbers          t
        company-tooltip-limit         20
        company-dabbrev-downcase      nil
        company-backends              '(company-c-headers
                                        company-elisp
                                        company-irony
                                        company-irony-c-headers
                                        company-jedi
                                        company-files
                                        company-capf)))

(use-package helm-files)

(use-package helm
  :ensure t
  :commands (helm-grep helm-files helm-swoop) 
  :bind (("M-x" . helm-M-x)
         ("\eb" . helm-buffers-list)
         ("C-s" . helm-swoop) ;; helm-swoop
         ("C-S" . helm-multi-swoop-all)
         :map helm-map
         ("<tab>" . helm-select-action)
         ("C-l"   . helm-execute-persistent-action)
         ("C-i"   . helm-previous-line)
         ("C-k"   . helm-next-line)
         :map helm-grep-mode-map
         ("<return>" . helm-grep-mode-jump-other-window)
         ("n"        . helm-grep-mode-jump-other-window-forward)
         ("p"        . helm-grep-mode-jump-other-window-backward)
         :map helm-find-files-map
         ("C-j" . helm-find-files-up-one-level)
         ("C-l" . helm-execute-persistent-action) 
         ("C-i" . helm-previous-line)
         ("C-k" . helm-next-line)
         :map isearch-mode-map
         ("C-s" . helm-swoop-from-isearch))       
  :config
  (use-package helm-swoop :ensure t)
  (if (version< "26.0.50" emacs-version)
      (eval-when-compile (require 'helm-lib)))
  (require 'helm-config)
  (setq helm-split-window-in-side-p            t ; open helm buffer inside current window, not occupy whole other window
        helm-move-to-line-cycle-in-source      t ; move to end or beginning of source when reaching top or bottom of source.
        helm-ff-search-library-in-sexp         t ; search for library in `require' and `declare-function' sexp.
        helm-scroll-amount                     8 ; scroll 8 lines other window using M-<next>/M-<prior>
        helm-ff-file-name-history-use-recentf  t
        helm-echo-input-in-header-line         t
        helm-multi-swoop-edit-save             t
        helm-swoop-split-with-multiple-windows t
        helm-swoop-split-direction             'split-window-vertically
        helm-swoop-speed-or-color              t))

(use-package rainbow-delimiters
  :ensure t
  :hook ((emacs-lisp-mode
          lisp-mode
          slime-repl-mode
          clojure-mode
          cider-repl-mode
          carp-mode
          haskell-mode
          c-mode
          c++-mode
          objc-mode
          python-mode
          web-mode)
         . rainbow-delimiters-mode))

(use-package highlight-symbol :ensure t)

(use-package all-the-icons :ensure t)
(use-package doom-modeline
  :ensure t
  :hook (after-init . doom-modeline-mode))

(use-package magit :ensure t)

(defun previous-blank-line ()
  (interactive)
  (search-backward-regexp "^[ \t]*\n"))

(defun next-blank-line ()
  (interactive)
  (forward-line)
  (search-forward-regexp "^[ \t]*\n")
  (forward-line -1))

(defadvice set-mark-command (after no-bloody-t-m-m activate)
  "Prevent consecutive marks activating bloody `transient-mark-mode'."
  (if transient-mark-mode (setq transient-mark-mode nil)))

(defadvice mouse-set-region-1 (after no-bloody-t-m-m activate)
  "Prevent mouse commands activating bloody `transient-mark-mode'."
  (if transient-mark-mode (setq transient-mark-mode nil))) 

(defun append-as-kill ()
  "Performs copy-region-as-kill as an append."
  (interactive)
  (append-next-kill) 
  (copy-region-as-kill (mark) (point)))

;; String -replace:
(defun timsa-replace-string (from-str to-str)
  "Replace a string without moving point."
  (interactive "sReplace: \nsReplace: %s  With: ")
  (save-excursion
    (replace-string from-str to-str)))
(define-key global-map [f8] 'timsa-replace-string)

(defun timsa-replace-in-region (old-word new-word)
  "Perform a replace-string in the current region."
  (interactive "sReplace: \nsReplace: %s  With: ")
  (save-excursion (save-restriction
                  (narrow-to-region (mark) (point))
                  (beginning-of-buffer)
                  (replace-string old-word new-word))))

(defun timsa-save-buffer ()
  (interactive)
  (save-excursion
    (save-restriction
      (widen)
      (untabify (point-min) (point-max))))
  (save-buffer))

(define-minor-mode timsa-custom-mode
  "Timsa's own general minor-mode"
  :lighter " Timsa-Custom"
  :init-value t
  :keymap (let ((map (make-keymap)))
               ;; Find-files:
               (define-key map "\ef" 'helm-find-files)

               ;; Navigation:
               (define-key map "\ew"     'other-window)
               (define-key map [C-right] 'forward-word)
               (define-key map [C-left]  'backward-word)
               (define-key map [C-up]    'previous-blank-line)
               (define-key map [C-down]  'next-blank-line)
               (define-key map [home]    'beginning-of-line)
               (define-key map [end]     'end-of-line)
               (define-key map [pgup]    'forward-page)
               (define-key map [pgdown]  'backward-page)

               ;; Deletion:
               (define-key map "\e " 'set-mark-command)
               (define-key map "\eq" 'append-as-kill)
               (define-key map "\ea" 'yank)
               (define-key map "\ez" 'kill-region)

               ;; ALT -ernatives (ha-ha!):
               (define-key map [M-up]    'previous-blank-line)
               (define-key map [M-down]  'next-blank-line)
               (define-key map [M-right] 'forward-word)
               (define-key map [M-left]  'backward-word)
               (define-key map "\e:"     'View-back-to-mark)
               (define-key map "\e;"     'exchange-point-and-mark)
               (define-key map [f9]      'first-error)
               (define-key map [f10]     'previous-error)
               (define-key map [f11]     'next-error)
               (define-key map "\eg"     'goto-line)
               (define-key map "\ej"     'imenu)
               (define-key map ""      'copy-region-as-kill)
               (define-key map ""      'yank)
               (define-key map ""      'nil)
               (define-key map ""      'rotate-yank-pointer)
               (define-key map "\eu"     'undo)
               (define-key map "\e6"     'UPCASE-word)
               (define-key map "\e^"     'capitalize-word)
               (define-key map "\el"     'timsa-replace-in-region)
               (define-key map "\eo"     'query-replace)
               (define-key map "\eO"     'timsa-replace-string)
               ;; \377 = alt-backspace
               (define-key map "\377"     'backward-kill-word)
               (define-key map [M-delete] 'kill-word)
               (define-key map "\e["      'start-kbd-macro)
               (define-key map "\e]"      'end-kbd-macro)
               (define-key map "\e'"      'call-last-kbd-macro)

               ;; Buffers
               (define-key map "\er" 'revert-buffer)
               (define-key map "\ek" 'kill-this-buffer)
               (define-key map [f5]  'make-without-asking)
               (define-key map "\es" 'save-buffer)
               map))

(add-hook 'minibuffer-setup-hook 
          (lambda () 
            (timsa-custom-mode 0)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants