Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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