Skip to content

Commit

Permalink
Bring over swap-window and find-symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
rdj committed Sep 29, 2011
1 parent 64046cc commit 39cd53b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
2 changes: 2 additions & 0 deletions init.el
Expand Up @@ -24,6 +24,8 @@
(load custom-file)

(require 'rdj-defs)
(require 'rdj-utils)

(require 'rdj-early-off)
(require 'rdj-package)
(require 'rdj-ido)
Expand Down
4 changes: 3 additions & 1 deletion rdj/rdj-bindings.el
@@ -1,14 +1,16 @@
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)

(global-set-key (kbd "C-c TAB") 'rdj-swap-windows)

(global-set-key (kbd "C-c C-g") 'magit-status)
(global-set-key (kbd "C-c C-i") 'toggle-case-fold-search)
(global-set-key (kbd "C-c C-r") 'recompile)
(global-set-key (kbd "C-c C-t") 'toggle-truncate-lines)
(global-set-key (kbd "C-c C-w") 'rdj-toggle-whitespace-cleanup)
(global-set-key (kbd "C-c C-z") 'rdj-smartsize-frame)

(global-set-key (kbd "M-`") 'other-frame)
(global-set-key (kbd "M-i") 'rdj-goto-symbol)
(global-set-key (kbd "M-g") 'goto-line)

(global-set-key (kbd "C-M-|") 'align-regexp)
Expand Down
63 changes: 63 additions & 0 deletions rdj/rdj-utils.el
@@ -0,0 +1,63 @@
(defun rdj-swap-windows ()
"If you have 2 windows, it swaps them." (interactive) (cond ((not (= (count-windows) 2)) (message "You need exactly 2 windows to do this."))
(t
(let* ((w1 (first (window-list)))
(w2 (second (window-list)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2)))
(set-window-buffer w1 b2)
(set-window-buffer w2 b1)
(set-window-start w1 s2)
(set-window-start w2 s1)))))

(defun rdj-goto-symbol (&optional symbol-list)
"Refresh imenu and jump to a place in the buffer using Ido."
(interactive)
(unless (featurep 'imenu)
(require 'imenu nil t))
(cond
((not symbol-list)
(let ((ido-mode ido-mode)
(ido-enable-flex-matching
(if (boundp 'ido-enable-flex-matching)
ido-enable-flex-matching t))
name-and-pos symbol-names position)
(unless ido-mode
(ido-mode 1)
(setq ido-enable-flex-matching t))
(while (progn
(imenu--cleanup)
(setq imenu--index-alist nil)
(rdj-goto-symbol (imenu--make-index-alist))
(setq selected-symbol
(ido-completing-read "Symbol? " symbol-names))
(string= (car imenu--rescan-item) selected-symbol)))
(unless (and (boundp 'mark-active) mark-active)
(push-mark nil t nil))
(setq position (cdr (assoc selected-symbol name-and-pos)))
(cond
((overlayp position)
(goto-char (overlay-start position)))
(t
(goto-char position)))))
((listp symbol-list)
(dolist (symbol symbol-list)
(let (name position)
(cond
((and (listp symbol) (imenu--subalist-p symbol))
(rdj-goto-symbol symbol))
((listp symbol)
(setq name (car symbol))
(setq position (cdr symbol)))
((stringp symbol)
(setq name symbol)
(setq position
(get-text-property 1 'org-imenu-marker symbol))))
(unless (or (null position) (null name)
(string= (car imenu--rescan-item) name))
(add-to-list 'symbol-names name)
(add-to-list 'name-and-pos (cons name position))))))))

(provide 'rdj-utils)

0 comments on commit 39cd53b

Please sign in to comment.