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
102 changes: 48 additions & 54 deletions layers/+spacemacs/spacemacs-defaults/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -356,46 +356,47 @@ Dedicated (locked) windows are left untouched."
(interactive "p")
(spacemacs/rotate-windows-forward (* -1 count)))

(if (configuration-layer/package-used-p 'winum)
(progn
(defun spacemacs/move-buffer-to-window (windownum follow-focus-p)
"Moves a buffer to a window, using the spacemacs numbering. follow-focus-p
controls whether focus moves to new window (with buffer), or stays on current"
(interactive)
(if (> windownum (length (window-list-1 nil nil t)))
(message "No window numbered %s" windownum)
(let ((b (current-buffer))
(w1 (selected-window))
(w2 (winum-get-window-by-number windownum)))
(unless (eq w1 w2)
(set-window-buffer w2 b)
(switch-to-prev-buffer)
(unrecord-window-buffer w1 b))
(when follow-focus-p
(select-window (winum-get-window-by-number windownum))))))

(defun spacemacs/swap-buffers-to-window (windownum follow-focus-p)
"Swaps visible buffers between active window and selected window.
follow-focus-p controls whether focus moves to new window (with buffer), or
stays on current"
(interactive)
(if (> windownum (length (window-list-1 nil nil t)))
(message "No window numbered %s" windownum)
(let* ((b1 (current-buffer))
(w1 (selected-window))
(w2 (winum-get-window-by-number windownum))
(b2 (window-buffer w2)))
(unless (eq w1 w2)
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(unrecord-window-buffer w1 b1)
(unrecord-window-buffer w2 b2)))
(when follow-focus-p (winum-select-window-by-number windownum)))))
;; when the winum package isn't used
(defun spacemacs//message-winum-package-required ()
(interactive)
(message (concat "This command requires the winum package," "\n"
"winum is part of the spacemacs-navigation layer."))))
(defun spacemacs//error-if-winum-missing ()
(unless (require 'winum nil t)
(user-error (concat "This command requires the winum package," "\n"
"winum is part of the spacemacs-navigation layer."))))

(defun spacemacs/move-buffer-to-window (windownum follow-focus-p)
"Moves a buffer to a window, using the spacemacs numbering.

FOLLOW-FOCUS-P controls whether focus moves to new window (with buffer),
or stays on current."
(spacemacs//error-if-winum-missing)
(if (> windownum (length (window-list-1 nil nil t)))
(message "No window numbered %s" windownum)
(let ((b (current-buffer))
(w1 (selected-window))
(w2 (winum-get-window-by-number windownum)))
(unless (eq w1 w2)
(set-window-buffer w2 b)
(switch-to-prev-buffer)
(unrecord-window-buffer w1 b))
(when follow-focus-p
(select-window (winum-get-window-by-number windownum))))))

(defun spacemacs/swap-buffers-to-window (windownum follow-focus-p)
"Swaps visible buffers between active window and selected window.

FOLLOW-FOCUS-P controls whether focus moves to new window (with buffer),
or stays on current"
(spacemacs//error-if-winum-missing)
(if (> windownum (length (window-list-1 nil nil t)))
(message "No window numbered %s" windownum)
(let* ((b1 (current-buffer))
(w1 (selected-window))
(w2 (winum-get-window-by-number windownum))
(b2 (window-buffer w2)))
(unless (eq w1 w2)
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(unrecord-window-buffer w1 b1)
(unrecord-window-buffer w2 b2)))
(when follow-focus-p (winum-select-window-by-number windownum))))

;; define and evaluate numbered functions:
;; spacemacs/winum-select-window-0 to 9
Expand All @@ -407,9 +408,8 @@ Dedicated (locked) windows are left untouched."
"Show a message stating that the winum package,"
"is part of the spacemacs-navigation layer.\n")
(interactive "P")
(if (configuration-layer/package-used-p 'winum)
(funcall ',(intern (format "winum-select-window-%s" i)) arg)
(spacemacs//message-winum-package-required)))))
(spacemacs//error-if-winum-missing)
(funcall ',(intern (format "winum-select-window-%s" i)) arg))))

;; define and evaluate three numbered functions:
;; buffer-to-window-1 to 9
Expand All @@ -420,21 +420,15 @@ Dedicated (locked) windows are left untouched."
(eval `(defun ,(intern (format "buffer-to-window-%s" n)) (&optional arg)
,(format "Move buffer to the window with number %i." n)
(interactive "P")
(if (configuration-layer/package-used-p 'winum)
(if arg
(spacemacs/swap-buffers-to-window ,n t)
(spacemacs/move-buffer-to-window ,n t))
(spacemacs//message-winum-package-required))))
(if arg
(spacemacs/swap-buffers-to-window ,n t)
(spacemacs/move-buffer-to-window ,n t))))
(eval `(defun ,(intern (format "move-buffer-window-no-follow-%s" n)) ()
(interactive)
(if (configuration-layer/package-used-p 'winum)
(spacemacs/move-buffer-to-window ,n nil)
(spacemacs//message-winum-package-required))))
(spacemacs/move-buffer-to-window ,n nil)))
(eval `(defun ,(intern (format "swap-buffer-window-no-follow-%s" n)) ()
(interactive)
(if (configuration-layer/package-used-p 'winum)
(spacemacs/swap-buffers-to-window ,n nil)
(spacemacs//message-winum-package-required))))))
(spacemacs/swap-buffers-to-window ,n nil)))))

(defun spacemacs/rename-file (filename &optional new-filename)
"Rename FILENAME to NEW-FILENAME.
Expand Down
69 changes: 34 additions & 35 deletions layers/+tools/ipython-notebook/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,39 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.


(when (configuration-layer/package-used-p 'company)
(defun spacemacs/ein-company (command &optional arg &rest ignore)
(interactive (list 'interactive))
(pcase command
(`interactive (company-begin-backend 'company-ein))
(`prefix
(and (--filter (and (boundp it) (symbol-value it) (eql it 'ein:notebook-mode))
minor-mode-list)
(company-grab-symbol-cons "\\.\\|->\\|::" 2)))
(`candidates
(lexical-let ((kernel (ein:get-kernel-or-error))
(arg arg)
(col (current-column)))
(cons :async
(lambda (cb)
(ein:kernel-complete
kernel
(string-trim-right (thing-at-point 'line t))
col
(list :complete_reply
(list #'spacemacs//ein-company-callback cb))
nil)))))))

(defun spacemacs/ein-company (command &optional arg &rest ignore)
(interactive (list 'interactive))
(pcase command
(`interactive (company-begin-backend 'company-ein))
(`prefix
(and (--filter (and (boundp it) (symbol-value it) (eql it 'ein:notebook-mode))
minor-mode-list)
(company-grab-symbol-cons "\\.\\|->\\|::" 2)))
(`candidates
(lexical-let ((kernel (ein:get-kernel-or-error))
(arg arg)
(col (current-column)))
(cons :async
(lambda (cb)
(ein:kernel-complete
kernel
(string-trim-right (thing-at-point 'line t))
col
(list :complete_reply
(list #'spacemacs//ein-company-callback cb))
nil)))))))
(defun spacemacs//ein-company-callback (args content metadata)
(let ((matches (append (plist-get content :matches) nil)))
(condition-case err
(progn
(funcall (car args) matches))
(error (error (format "Error %s running ein company completer." err))))))

(defun spacemacs//ein-company-callback (args content metadata)
(let ((matches (append (plist-get content :matches) nil)))
(condition-case err
(progn
(funcall (car args) matches))
(error (error (format "Error %s running ein company completer." err))))))
(defun spacemacs//ein-setup-company ()
(if (eq ein-backend 'jupyter)
(spacemacs|add-company-backends
:backends spacemacs/ein-company
:modes ein:notebook-mode
:append-hooks nil
:call-hooks t))))
(defun spacemacs//ein-setup-company ()
(if (eq ein-backend 'jupyter)
(spacemacs|add-company-backends
:backends spacemacs/ein-company
:modes ein:notebook-mode
:append-hooks nil
:call-hooks t)))
33 changes: 15 additions & 18 deletions layers/+tools/translate/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,20 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

(when (and (configuration-layer/package-used-p 'translate-mode)
(configuration-layer/package-used-p 'go-translate))
(defun translate/translate-current-reference-paragraph ()
"Show all available translations of the reference paragraph at point in a pop-up frame."
(interactive)
(gt-start translate//paragraph-translator))

(defun translate/translate-current-reference-paragraph ()
"Show all available translations of the reference paragraph at point in a pop-up frame."
(interactive)
(gt-start translate//paragraph-translator))
(defun translate/translate-word-at-point ()
"Pop-up translations of the word at point."
(interactive)
(gt-start translate//word-translator))

(defun translate/translate-word-at-point ()
"Pop-up translations of the word at point."
(interactive)
(gt-start translate//word-translator))

(defun translate//set-translate-mode-paragraph-functions ()
(cond ((eq major-mode 'markdown-mode)
(setq translate-forward-paragraph-function 'markdown-forward-paragraph
translate-backward-paragraph-function 'markdown-backward-paragraph))
((eq major-mode 'org-mode)
(setq translate-forward-paragraph-function 'org-forward-paragraph
translate-backward-paragraph-function 'org-backward-paragraph)))))
(defun translate//set-translate-mode-paragraph-functions ()
(cond ((eq major-mode 'markdown-mode)
(setq translate-forward-paragraph-function 'markdown-forward-paragraph
translate-backward-paragraph-function 'markdown-backward-paragraph))
((eq major-mode 'org-mode)
(setq translate-forward-paragraph-function 'org-forward-paragraph
translate-backward-paragraph-function 'org-backward-paragraph))))
Loading