Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun my-multi-toggle ()
- (interactive)
- (set-buffer-multibyte (not enable-multibyte-characters)))
- (global-set-key (kbd "C-~") 'my-multi-toggle)
- (defun poff-zap ()
- "Get the byte offset of point - A prototye, tested minimally only with UTF-16LE"
- (interactive)
- (let ((linect (- (line-number-at-pos) 1)) ;; line count to point
- (choncl (- (point) (point-at-bol))) ;; characters to point on current line
- (chrpnl 0) ;; chars per newline
- (bytpch 0) ;; bytes per char
- (bytpnl 0) ;; bytes per newline
- (offset 0) ;; the byte offset
- (coding (car (split-string (symbol-name buffer-file-coding-system) "-")))
- (format (cadr (split-string (symbol-name buffer-file-coding-system) "-"))))
- (case (coding-system-eol-type buffer-file-coding-system)
- ('0 (setq chrpnl 1)) ;; unix
- ('1 (setq chrpnl 2)) ;; dos
- ('2 (setq chrpnl 1)) ;; mac
- (t))
- (if (> chrpnl 0)
- (cond
- ((string= "utf" coding)
- (cond
- ((string= "8" format)
- (progn
- (setq bytpch -1)
- ;; need to do an actual byte count
- ;; using a UTF-8 parser
- ;; ...plus a BOM check(?)
- ))
- ((or
- (string= "16" format)
- (string= "16le" format))
- (progn
- (setq bytpch 2)
- (if (= 2 chrpnl) (setq offset linect))
- (setq offset (+ offset (point)))
- (setq offset (* offset bytpch))
- ))
- (t)))
- (t)))
- (message (concat
- "poff-zap: " (number-to-string bytpch) " bytes-per-charn"
- " " (number-to-string chrpnl) " chars-per-newlinern"
- " " (number-to-string bytpnl) " bytes-per-newlinern"
- " " (number-to-string (point)) " point-emacsn"
- " " (number-to-string offset) " offset poff-zapn"
- " " (symbol-name buffer-file-coding-system) ))
- ))
- (global-set-key (kbd "C-#") 'poff-zap)
- M-: (1- (position-bytes (point)))
- (defun wh/byte-offset-at-point ()
- "Report the byte offset (0-indexed) in the file
- corresponding to the position of point."
- (interactive)
- (message "byte offset: %d" (1- (position-bytes (point)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement