Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring over swap-window and find-symbol
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |