-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepc-navigation.el
More file actions
53 lines (46 loc) · 1.79 KB
/
epc-navigation.el
File metadata and controls
53 lines (46 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;;; -*- coding: utf-8; lexical-binding: t -*-
;;; Author: ywatanabe
;;; Timestamp: <2025-04-24 14:17:28>
;;; File: /home/ywatanabe/.emacs.d/lisp/emacs-python-config/epc-navigation.el
;;; Copyright (C) 2025 Yusuke Watanabe (ywatanabe@alumni.u-tokyo.ac.jp)
(require 'cl-lib)
(defun epc-navigation-cycle (&optional step)
"Cycle through buffers in python-mode."
(interactive "p")
(let* ((current-buffer (current-buffer))
(python-buffers
(seq-filter
(lambda (buf)
(with-current-buffer buf
(eq major-mode 'python-mode)))
(buffer-list)))
(current-index
(cl-position current-buffer python-buffers :test 'eq))
(buffer-count (length python-buffers))
(next-index (mod (+ current-index (or step 1)) buffer-count)))
(when python-buffers
(switch-to-buffer (nth next-index python-buffers)))))
(defun epc-navigation-toggle-source-test ()
"Toggle between Python source and test files."
(interactive)
(let* ((current-file (buffer-file-name))
(is-test (string-match-p "/tests/" current-file))
(target-path
(if is-test
(replace-regexp-in-string
"/tests/" "/src/"
(replace-regexp-in-string "test_" "" current-file))
(replace-regexp-in-string
"/src/" "/tests/"
(concat (file-name-directory current-file)
"test_"
(file-name-nondirectory current-file))))))
(if (file-exists-p target-path)
(find-file target-path)
(message "Target file does not exist: %s" target-path))))
(provide 'epc-navigation)
(when
(not load-file-name)
(message "epc-navigation.el loaded."
(file-name-nondirectory
(or load-file-name buffer-file-name))))