Skip to content

Instantly share code, notes, and snippets.

@kidd
Created September 8, 2011 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidd/1205117 to your computer and use it in GitHub Desktop.
Save kidd/1205117 to your computer and use it in GitHub Desktop.
shortcuts to narrow buffers to classes
(require 'smalltalk-mode)
(setq auto-mode-alist
(append '(("\\.st\\'" . smalltalk-mode))
auto-mode-alist))
(defun smalltalk-narrow-to-object ()
;;(interactive)
(let* ((from (save-excursion (or (search-backward "! !" (point-min) t) (point-min))))
(to (save-excursion (or (progn (search-forward "! !" (point-max) t)) (point-max)))))
(narrow-to-region from to)))
(defun go-to-next-class ()
(interactive)
(widen)
(let ((to (save-excursion (or (search-forward "! !" (point-max) t) (point-max)))))
(when (not (= to (point-max)))
(search-forward "! !" (point-max) t)
(re-search-forward "^\\w" (point-max) t))
(smalltalk-narrow-to-object)))
(defun go-to-prev-class ()
(interactive)
(widen)
(let ((to (save-excursion (or (search-backward "! !" (point-min) t) (point-min)))))
(when (not (= to (point-min)))
(search-backward "! !" (point-min) t)
(re-search-backward "\\w" (point-min) t))
(smalltalk-narrow-to-object)))
(add-hook 'smalltalk-mode-hook
(lambda ()
(local-set-key (kbd "C-c n") 'go-to-next-class)
(local-set-key (kbd "C-c p") 'go-to-prev-class)
(local-set-key (kbd "C-c a") 'widen)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment