diff --git a/emacs/.emacs.d/packages/aimenu/aimenu.el b/emacs/.emacs.d/packages/aimenu/aimenu.el index 498d0b4..59cb4df 100644 --- a/emacs/.emacs.d/packages/aimenu/aimenu.el +++ b/emacs/.emacs.d/packages/aimenu/aimenu.el @@ -48,12 +48,15 @@ "Return a hash for the given string STR using SHA-256." (secure-hash 'sha256 str)) -(defun aimenu-get-buffer-with-line-numbers (buffer) +(defun aimenu-get-buffer-with-line-numbers (buffer &optional start end) "Return the contents of BUFFER with line numbers added to each line." (with-temp-buffer - (insert-buffer-substring buffer) + (insert-buffer-substring buffer start end) (goto-char (point-min)) - (let ((line-number 1)) + (let ((line-number (1+ (or (when start + (with-current-buffer buffer + (line-number-at-pos start))) + 0)))) (while (not (eobp)) (insert (format "%d: " line-number)) (forward-line 1) @@ -110,7 +113,10 @@ If ARG is non-nil, prompt for an instruction for generating the outline." (let* ((instruction (if arg (read-string "Instruction: ") nil)) - (buffer-contents (aimenu-get-buffer-with-line-numbers (current-buffer))) + (buffer-contents + (apply #'aimenu-get-buffer-with-line-numbers (current-buffer) + (when (region-active-p) + (list (region-beginning) (region-end))))) (prompt (if instruction (concat buffer-contents "\n\nInstruction: " instruction) buffer-contents))